Snippets - GD
Resize an image - Anthony 14/6/2008
This will resize an image keeping its aspect ratio and save it. You will notice it is a lot more complicated than using Imagemagick - check out the link.
<?php// Set the path to the image to resize$input_image = "House.jpg";// Get the size of the original image into an array$size = getimagesize( $input_image );// Set the new width of the image$thumb_width = "200";// Calculate the height of the new image to keep the aspect ratio$thumb_height = ( int )(( $thumb_width/$size[0] )*$size[1] );// Create a new true color image in the memory$thumbnail = ImageCreateTrueColor( $thumb_width, $thumb_height );// Create a new image from file$src_img = ImageCreateFromJPEG( $input_image );// Create the resized imageImageCopyResampled( $thumbnail, $src_img, 0, 0, 0, 0, $thumb_width, $thumb_height, $size[0], $size[1] );// Save the image as resized.jpgImageJPEG( $thumbnail, "resized.jpg" );// Clear the memory of the tempory imageImageDestroy( $thumbnail );?>