note 53760 added to function.imagecopyresized

From: Date: Sun, 12 Jun 2005 10:53:23 +0000
Subject: note 53760 added to function.imagecopyresized
Groups: php.notes 
Request: Send a blank email to php-notes+get-90288@lists.php.net to get a copy of this message
I spent last night getting unsuccessful results from this function until I found this note of fluffle <<at>> gmail on the imagecopyresampled page, I have made a slight modification, so you can just cut and paste. Just to clarify that src_w and src_h do not necessarily need to be the source image width and height, as they specify the size of the rectangle cropped from the source picture, with its top left corner situated at (src_x, src_y). For example, the code below crops a jpeg image to be square, with the square situated in the centre of the original image, and then resizes it to a 100x100 thumbnail. function ($image_filename, $thumb_location, $image_thumb_size){ //@$image_filename - the filename of the image you want //to get a thumbnail for (relative to location of this //function). //@$thumb_location - the url (relative to location of this //function) to save the thumbnail. //@$image_thumb_size - the x-y dimension of your thumb //in pixels. list($ow, $oh) = getimagesize($image_filename); $image_original = imagecreatefromjpeg($image_filename); $image_thumb = imagecreatetruecolor($image_thumb_size,$image_thumb_size); if ($ow > $oh) { $off_w = ($ow-$oh)/2; $off_h = 0; $ow = $oh; } elseif ($oh > $ow) { $off_w = 0; $off_h = ($oh-$ow)/2; $oh = $ow; } else { $off_w = 0; $off_h = 0; } imagecopyresampled($image_thumb, $image_original, 0, 0, $off_w, $off_h, 100, 100, $ow, $oh); imagejpeg($image_thumb, $thumb_location); }//end function ---- Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53760 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53760&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53760&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53760&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53760&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53760&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53760&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90288) next »