All pastes #806746 Raw Edit

Image Resizer

public php v1 · immutable
·published 2007-12-05 21:58 UTC
rendered paste body
		function resizeImage($filename, $writeto, $max_width, $max_height)		{			list($orig_width, $orig_height) = getimagesize($filename);			$width = $orig_width;			$height = $orig_height;			if ($height > $max_height) {				$width = ($max_height / $height) * $width;				$height = $max_height;			}			if ($width > $max_width) {				$height = ($max_width / $width) * $height;				$width = $max_width;			}			$image_p = imagecreatetruecolor($width, $height);			$image = imagecreatefromjpeg($filename);			imagecopyresampled($image_p, $image, 0, 0, 0, 0,			$width, $height, $orig_width, $orig_height);			$image_p = imagejpeg($image_p, $writeto, 100);		}