note 58166 added to function.getimagesize

From: Date: Wed, 26 Oct 2005 12:10:42 +0000
Subject: note 58166 added to function.getimagesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-97615@lists.php.net to get a copy of this message
This is a useful function to display a thumbnail of a whatever image. This piece of code has been lightly modified from an example found on <b>NYPHP.ORG</B>. This function can build a thumbnail of any size you want and display it on your browser! Hope it can be useful for you guys! <?php function makeThumbnail($o_file, $t_ht = 100) { $image_info = getImageSize($o_file) ; // see EXIF for faster way switch ($image_info['mime']) { case 'image/gif': if (imagetypes() & IMG_GIF) { // not the same as IMAGETYPE $o_im = imageCreateFromGIF($o_file) ; } else { $ermsg = 'GIF images are not supported<br />'; } break; case 'image/jpeg': if (imagetypes() & IMG_JPG) { $o_im = imageCreateFromJPEG($o_file) ; } else { $ermsg = 'JPEG images are not supported<br />'; } break; case 'image/png': if (imagetypes() & IMG_PNG) { $o_im = imageCreateFromPNG($o_file) ; } else { $ermsg = 'PNG images are not supported<br />'; } break; case 'image/wbmp': if (imagetypes() & IMG_WBMP) { $o_im = imageCreateFromWBMP($o_file) ; } else { $ermsg = 'WBMP images are not supported<br />'; } break; default: $ermsg = $image_info['mime'].' images are not supported<br />'; break; } if (!isset($ermsg)) { $o_wd = imagesx($o_im) ; $o_ht = imagesy($o_im) ; // thumbnail width = target * original width / original height $t_wd = round($o_wd * $t_ht / $o_ht) ; $t_im = imageCreateTrueColor($t_wd,$t_ht); imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht); imageJPEG($t_im); imageDestroy($o_im); imageDestroy($t_im); } return isset($ermsg)?$ermsg:NULL; } ?> Here the code to call the function: <? header("Content-type: image/jpeg"); makeThumbnail("http://it2.php.net/images/php.gif", 300); ?> ---- Manual Page -- http://www.php.net/manual/en/function.getimagesize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58166 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58166&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58166&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58166&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58166&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58166&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58166&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58166&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58166&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97615) next »