PHP Image Plugin

PHP Image Plugin

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.

Image Info

This will return basic info about a specific image including image type, width, height and size (in bytes, kilobytes and megabytes).

echo $image->info('img/swirly.png');


  • Image type: png
  • Width: 1920
  • Height: 1280
  • Size in bytes: 1285926
  • Size in kilobytes: 1285.93
  • Size in megabytes: 1.29

Image Scale

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);


Image Resize

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);


Image Crop

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).



Image Contents

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).

Text List

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.


Visual List

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.


Array List

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 */
    [0] => colorful.jpg
    [1] => field.jpg
    [2] => pirate.jpg
    [3] => planet.jpg
    [4] => tado.jpg
    [5] => tornado.jpg
    [6] => turtle.jpg
    [7] => water.jpg

More Files From the PHP Plugin Suite


Image Plugin

Map + Weather Plugin

Twitter Plugin

Video Plugin

Weather Plugin

pose css