note 49902 added to function.imagejpeg
| From: | r dot duclos at chello dot fr | Date: | Fri, 11 Feb 2005 14:41:06 +0000 |
| Subject: | note 49902 added to function.imagejpeg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84827@lists.php.net to get a copy of this message | ||
Hy, here is a little code for generate a thumbnail, very good quality. Enjoy it !
<?php
function miniature($pict, $dest_pict){
$handle = @imagecreatefromjpeg($pict);
$x=imagesx($handle);
$y=imagesy($handle);
if($x > $y){
$max = $x;
$min = $y;
}
if($x <= $y){
$max = $y;
$min = $x;
}
//$size_in_pixel : Size max of the label in pixel. The size of the picture being
//proportional to the original, this value define maximum size
//of largest side with dimensions of the picture. Sorry for my english !
//Here $size_in_pixel = 100 for a thumbnail.
$size_in_pixel = '100';
$rate = $max/$size_in_pixel;
$final_x = $x/$rate;
$final_y = $y/$rate;
if($final_x > $x) {
$final_x = $x;
$final_y = $y;
}
$final_x = ceil($final_x);
$final_y = ceil($final_y);
$black_picture = imageCreatetruecolor($final_x,$final_y);
imagefill($black_picture,0,0,imagecolorallocate($black_picture, 255, 255, 255));
imagecopyresampled($black_picture, $handle, 0, 0, 0, 0,$final_x, $final_y, $x, $y);
if(!@imagejpeg($black_picture,$dest_pict.'/mini_'.$pict, $size_in_pixel))
imagestring($black_picture, 1, $final_x-4, $final_y-8, ".",
imagecolorallocate($black_picture,0,0,0));
//The number is the quality of the result picture
imagejpeg($black_picture,'', '100');
imagedestroy($handle);
imagedestroy($black_picture);
}
$pict = "PICT7024.jpg";
$dest_pict = "D:/Program Files/EasyPHP1-7/www/test";
miniature($pict, $dest_pict);
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagejpeg.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49902
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49902&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49902&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49902&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49902&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49902&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49902&report=yes
Search -- http://master.php.net/manage/user-notes.php