
Get the image width value in pixels $image_width = $image->getWidth() Ĭheck if the image width is greater than the width you want to rezize. (you can get the latest version from here : ) require_once("lib/SimpleImage.php") All you should need for this is the simple image class and the image file location on the server. Here is how i resize images if they are over a certain width.
#SIMPLEIMAGE PHP HOW TO#
I always forget how to do this even though its pretty simple once you know what to do. How to resize images with PHP using the SimpleImage Library Use is wisely.Image Resizing with PHP and SimpleImage Library This script can easily be modified to display files other than images. Pulls in the image dimension attributes using PHP’s getimagesize and displays them. If an image is selected, the image is displayed. Filters out everything except the file extensions that you allow. Starts looping through the array names $files. If you wanted to set it up to read a sub-directory, you could do that by changing the path here and on lines 49 and 57. Yeah, that can happen if you use the Google or Yahoo toolbar with your browser. We included the robots meta tag to prevent the script from showing up in a search engine.

Line 2 reads the image file name that is passed by the form variable. This is a recursive script, which means that it calls itself when processing the selection.

If(($extension = ".gif") OR ($extension = ".jpg") OR ($extension = ".png")) $extension = strtolower(substr($files, -4)) it would be a good idea to name the script using an obscure name that only you will remember if you do not want anyone else to find the script. Scroll through the list, select an image name and click the Select button to display the image information. It offers a count of the total number of images found, as well and the height and width dimensions for a selected image. You can name this script anything that you wish and just drop it into an image directory.
#SIMPLEIMAGE PHP MANUAL#
There are options in the manual page for filtering out other types of files. Please read the section on Booleans for more information. This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. It is usually harmless to expose the names of images, but may not be harmless to expose other file types.įor more details about scandir, see the PHP Manual for scandir. pregmatch () returns 1 if the pattern matches given subject, 0 if it does not, or false on failure. It is important to filter out any file types that you do not want to expose to others, just in case someone happens to find your image viewing script. scandir also pulls in the dot designations for the current directory and sub-directories (. By default, the array is sorted in ascending order, but if can also sort in descending order. scandir reads the entire contents of a directory into a sorted array.

The scandir function replaced the older dir class and makes the process much simpler. The scandir function that we used is only available in PHP 5.x and newer versions, so you do need to make sure that the server runs PHP 5. The script will read and display the image file names in that directory. We wrote this simple PHP script that can be dropped into any image directory on a web server that runs PHP 5. The client is not tech-savvy and wanted to find a way to view the images on her server. We recently picked up a client whose web designers stored hundreds of images on her web server.
