note 98560 modified in function.imagecopyresampled by danbrown

From: Date: Fri, 25 Jun 2010 15:16:23 +0000
Subject: note 98560 modified in function.imagecopyresampled by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170442@lists.php.net to get a copy of this message
Function to resize an image. <?php function resizeImage($originalImage,$toWidth,$toHeight) { list($width, $height) = getimagesize($originalImage); $xscale=$width/$toWidth; $yscale=$height/$toHeight; if ($yscale>$xscale){ $new_width = round($width * (1/$yscale)); $new_height = round($height * (1/$yscale)); } else { $new_width = round($width * (1/$xscale)); $new_height = round($height * (1/$xscale)); } $imageResized = imagecreatetruecolor($new_width, $new_height); $imageTmp = imagecreatefromjpeg ($originalImage); imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $imageResized; } ?> --was-- ..........how to resize an image ..........function..... function resizeImage($originalImage,$toWidth,$toHeight) { list($width, $height) = getimagesize($originalImage); $xscale=$width/$toWidth; $yscale=$height/$toHeight; if ($yscale>$xscale){ $new_width = round($width * (1/$yscale)); $new_height = round($height * (1/$yscale)); } else { $new_width = round($width * (1/$xscale)); $new_height = round($height * (1/$xscale)); } $imageResized = imagecreatetruecolor($new_width, $new_height); $imageTmp = imagecreatefromjpeg ($originalImage); imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $imageResized; } http://php.net/manual/en/function.imagecopyresampled.php

« previous php.notes (#170442) next »