note 67892 added to function.imagecreate

From: Date: Thu, 06 Jul 2006 04:00:51 +0000
Subject: note 67892 added to function.imagecreate
Groups: php.notes 
Request: Send a blank email to php-notes+get-114479@lists.php.net to get a copy of this message
I thought of several width/height methods for thumbnails, and have settled on using a fixed (approximately) area. That way the image will have generally a good size but retain its aspect ratio. This probably isn't good for an image gallery, but works nicely for thumbnails displayed inline. <?php list ($width, $height, $type, $attr) = getimagesize ("img_name"); $orig = imagecreatefromstring (file_get_contents ("img_name")); // In any two similar polygons, the ratio of // the squares of any corresponding sides is // proportional to the areas of the given // polygons. This algo gives a height and // width of a thumbnail with a total area of // 22500 pixels, or the area of a 150 by 150 // pixel image. $sideratio = sqrt (22500 / ($width * $height)); $thumbwidth = round ($width * $sideratio); $thumbheight = round ($height * $sideratio); $thumbnail = imagecreatetruecolor ($thumbwidth, $thumbheight); imagecopyresampled ($thumbnail, $orig, 0, 0, 0, 0, $width, $height, $thumbwidth, $thumbheight); imagedestroy ($orig); ob_start (); imagejpeg ($thumbnail); $yourthumbnail = ob_get_clean (); ?> ---- Server IP: 64.71.164.2 Probable Submitter: 67.176.82.241 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.imagecreate.php Edit -- http://master.php.net/note/edit/67892 Del: integrated -- http://master.php.net/note/delete/67892/integrated Del: useless -- http://master.php.net/note/delete/67892/useless Del: bad code -- http://master.php.net/note/delete/67892/bad+code Del: spam -- http://master.php.net/note/delete/67892/spam Del: non-english -- http://master.php.net/note/delete/67892/non-english Del: in docs -- http://master.php.net/note/delete/67892/in+docs Del: other reasons-- http://master.php.net/note/delete/67892 Reject -- http://master.php.net/note/reject/67892 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114479) next »