public marks

PUBLIC MARKS from imelgrat with tag image

19 July 2007 04:00

Resize image proportionally with optional background color using PHP and GD

(via)
This is an update of a previous post, which described a PHP function for resizing images using the GD library and some clever math calculations to determine the optimal width and height. This function resizes a picture to the chosen size while maintaining the original image’s proportions, thus avoiding image distortion. In the previous version, the function always used a black background, so images that needed to be cropped would sometimes display black bars on the sides. This updated function allows the user to select the background color, passed as an array of 3 integer numbers (RED, GREEN, BLUE). This makes it eay to “blend” the resized images to the page background, without any black bars on the sides. This new version has been fully documented (using PHPDoc-style comments).

17 July 2007 16:00

Resize image proportionally (cropping it if necessary)

This function will resize an image to the specified width and height without distorting it and in most cases without adding black regions to the image (by cropping the image to the desired size). It is very useful for creating picture thumbnails of a given size, regardless of the image’s original dimensions.