note 67892 deleted from function.imagecreate by bjori

From: Date: Thu, 06 Jul 2006 11:13:25 +0000
Subject: note 67892 deleted from function.imagecreate by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-114495@lists.php.net to get a copy of this message
Note Submitter: Peter Reason: 5 ---- 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 (); ?>

« previous php.notes (#114495) next »