This plugin includes several image related functions. You can modify an image (resize, crop, scale), get information (dimensions, type & file size), or automatically create a display or a list of all images in a given directory. Most of the classes require that GD be enabled in PHP, otherwise there’s not any special requirements. The examples on this page are using static images, and the returned data simulated as CodeCanyon obviously doesn’t allow running PHP scripts on this page. Visit the example page to see the images actually being modified on the fly.
This will return basic info about a specific image including image type, width, height and size (in bytes, kilobytes and megabytes).
- Image type: png
- Width: 1920
- Height: 1280
- Size in bytes: 1285926
- Size in kilobytes: 1285.93
- Size in megabytes: 1.29
The function will scale an image proprtionally to a specific width. Example resizes 1920×1280 image to 300 pixels wide.
$image->scale('img/swirly.png', $dest='img/scale.png', $width=300);
The function will resize an image to a specific width and height (may not be proportional). Example resizes 1920×1280 image to 200×300.
$image->resize('img/swirly.png', $dest='img/resize.png', $width=200, $height300);
This crops an image to specific dimensions. In this example the original 1920×1280 image is cropped to 690×770 (400px from the left and 300px from the top).
This final function will create a list of all images within a given directory. You can choose to display it either as a textual list, or to actually display all of the images (with an optional max-width setting).
The default settings will output a text list of all images in a directory. By default each image will be enclosed in anchor tags linking to the file, proceeded by a line break “
”. If you prefer, you can set $line_break to false and you’ll get a coma separated list instead. If you just want to display a list without linking to the file, set $link to false.
Instead of just listing the images in a directory, you can also choose to display the actual images. There’s a max-width setting (set to 160px in the example) if you want to keep the images from getting too big. Each image also has a class of “img_list” if you want to do any additional styling with css. Finally, there’s also a “root” setting in case you need modify the display location. For example, my CodeIgniter URI rewritting can sometimes confuse things (with the browser and php looking for the file at different locations), so I need to modify the display path on this page.
The final option will return the list as an array instead of displaying the data so you’re free to format it however you like.
print_r($image->contents('dirname', $list='array')) /* Data returned by the image contents array */ Array (  => colorful.jpg  => field.jpg  => pirate.jpg  => planet.jpg  => tado.jpg  => tornado.jpg  => turtle.jpg  => water.jpg )
More Files From the PHP Plugin Suite