note 81856 added to function.imagecopyresampled

From: Date: Sun, 16 Mar 2008 18:58:17 +0000
Subject: note 81856 added to function.imagecopyresampled
Groups: php.notes 
Request: Send a blank email to php-notes+get-137109@lists.php.net to get a copy of this message
A small thumb script. Lets you specify max height and width. The thumb will always be of a rectangular shape while the image itself retains it's proportions. Very clean. <?php // The file $filename = 'a.jpg'; // Set a maximum height and width $width = 80; $height = 80; $thumbsize = 80; // Content type header('Content-type: image/jpeg'); // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($thumbsize, $thumbsize); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, -($width/2) + ($thumbsize/2), -($height/2) + ($thumbsize/2), 0, 0, $width, $height, $width_orig, $height_orig); // Output imagejpeg($image_p, null, 100); ?> ---- Server IP: 213.181.110.1 Probable Submitter: 157.157.117.23 ---- Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php Edit -- https://master.php.net/note/edit/81856 Del: integrated -- https://master.php.net/note/delete/81856/integrated Del: useless -- https://master.php.net/note/delete/81856/useless Del: bad code -- https://master.php.net/note/delete/81856/bad+code Del: spam -- https://master.php.net/note/delete/81856/spam Del: non-english -- https://master.php.net/note/delete/81856/non-english Del: in docs -- https://master.php.net/note/delete/81856/in+docs Del: other reasons-- https://master.php.net/note/delete/81856 Reject -- https://master.php.net/note/reject/81856 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137109) next »