note 43560 added to function.imagejpeg

From: Date: Fri, 25 Jun 2004 13:42:22 +0000
Subject: note 43560 added to function.imagejpeg
Groups: php.notes 
Request: Send a blank email to php-notes+get-71668@lists.php.net to get a copy of this message
Here is the simple, but powerful script for creating thumbnails on the fly. You can include the script directly to www page - just put it in <img src= tag. with width 150pix. This resizer respects the ASPECT RATIO. Here is the script: <?php // Use it this way: resize.php?pic=imageurl&width=width_in_pixels // kokesh@kokeshnet.com 2004 header("Content-type: image/jpeg"); $im = imagecreatefromjpeg($pic); $orange = imagecolorallocate($im, 220, 210, 60); $px = (imagesx($im) - 7.5 * strlen($string)) / 2; $old_x=imageSX($im); $old_y=imageSY($im); $new_w=(int)($width); if (($new_w<=0) or ($new_w>$old_x)) { $new_w=$old_x; } $new_h=($old_x*($new_w/$old_x)); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } $thumb=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresized($thumb,$im,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); imagejpeg($thumb,"",90); imagedestroy($thumb); ?> ---- Manual Page -- http://www.php.net/manual/en/function.imagejpeg.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43560 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43560&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43560&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#71668) next »