8.5. Resizing Images

Resizing images is a little tricky, but you can break the process down into small sections. Resizing an image requires several steps:

  • Determine new dimensions based on the defined maximum dimensions

  • Determine which image handling functions are necessary for resampling

  • Resample the image at the proper size

8.5.1. Determining the New Image Dimensions

Begin the process of resizing an image by determining what size the image should actually be. Unfortunately, you can't simply tell your script that all images should be 350 pixels by 240 pixels because forcing an image to match dimensions that aren't proportional to an image's original dimensions causes distortion, which doesn't look good.

Instead, you need to determine the proportional ...

Get PHP for Absolute Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.