Archive for April 2009

Resize and Crop Photos with PHP’s GD Library

Saturday, April 18th, 2009 by Joyce Johnston

I was recently working on a personal project where I wanted to upload photos and, at the same time, carry out the following tasks:

  • create a thumbnail of the uploaded image
  • resize the image if either its width or height were over 600px and store the resized image rather than the original
  • store a caption for the image in a database table

I considered using phpThumb; however, I ran into problems with ImageMagick when I tried saving an image to a file. Googling the problem suggested that I needed to use an older version of ImageMagick, which I was reluctant to do. So I turned to PHP’s GD library, and wrote a class to handle the image-related tasks.

Read more »