The SimpleImage Class for PHP

November 15, 2011

If you love working with PHP but hate the GD library, you’ll love the Simple Image PHP class we’re releasing today. This class takes the headache out of dealing with images and features over 25 useful methods.

The class is incredibly simple to use.  The following two lines will load image.jpg, flip it horizontally, rotate it 90 degrees, shrink it to fit within a 320×200 box, apply a sepia effect, convert it to a GIF, and save it to result.gif:

$img = new SimpleImage('image.jpg');
$img->flip('x')->rotate(90)->best_fit(320, 200)->sepia()->save('result.gif');

Here’s a list of the supported methods:

  • flip() – flips an image vertically or horizontally
  • rotate() – rotates an image at the specified angle
  • auto_orient() – adjusts the orientation based on the image’s EXIF data
  • resize() – resizes an image to the specified width/height
  • fit_to_width() – proportionally resizes an image to the specified width
  • fit_to_height() – proportionally resizes an image to the specified height
  • best_fit() – proportionally resizes an image to fit within the specified width/height
  • crop() – crop an image from x1/y1 to x2/y2
  • square_crop() – trim the image to a square and resize to the specified size
  • desaturate() – convert the image to grayscale
  • invert() – invert the image
  • brightness() – adjust the image’s brightness
  • contrast() – adjust the image’s contrast
  • colorize() – apply the colorize filter
  • edges() – apply the edges filter
  • emboss() – apply the emboss filter
  • mean_remove() – apply the mean removal filter
  • blur() – apply selective or gaussian blur to the image
  • sketch() – apply the sketch filter
  • smooth() – apply the smooth filter
  • pixelate() – pixelate the image to blocks of the specified size
  • sepia() – apply a simulated sepia effect
  • overlay() – overlay one image onto another to create a watermark effect
  • text() – Add text to the image

Download

This project is actively maintained on GitHub. Please submit all issues and contributions to the project page. Licensed under both the MIT and the GNU GPL licenses.

Download the latest version from GitHub

Discussion

  1. Is it possible to change the file path for saving the image?

    October 1st, 2012hanna
  2. Hanna, just specify the full file name in the save() method.

    October 10th, 2012Cory LaViska
  3. Is it possible to have the rotate method add a transparent background instead of an opaque one?

    November 22nd, 2012Andrei
  4. Perfect! Exactly what I’ve been looking for, works like a charm. Many thanks for that cool class! :)

    January 4th, 2013Jochen C.
  5. Hi, you have done a good job! I just want to have one more addition on this, that is can you have resize proportionally method implemented? Also it’ll be beautiful to have text manipulation class with various font style and shapes.

    March 18th, 2013Manoj
  6. You can use fit_to_width(), fit_to_height(), or best_fit() to proportionally resize an image depending on your needs.

    March 22nd, 2013Cory LaViska