Nicholas Skinner

Freelance website and web application developer

PHP Class: Image Resizing

Image Resize Code ScreenshotFor a new website project I had the need to resize images in PHP so decided to rewrite some of my years old image resizing functions to more be up-to-date with my current coding practices.

Class supports source/destination images as jpeg, png, or gif automatically identifying the type from the filename, and allows for:

  • Proportional resizing based on a provided width or height (but not both) resulting in e.g. a 200px wide image, and a height proportionally scaled to the original.
  • Fixed proportional resizing with cropping based on a provided width and height resulting in an image that will first be scaled and then cropped from the centre to exactly match both provided dimensions.

[Download: img.php]

Leave a Reply