1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| function copy_and_resize($src,$dest_file,$width,$height,$quality=50)
{
if(!$source = imagecreatefromjpeg($src))
{
echo "Warning : cannot create image from $src <BR>";
return false;
}
$imageX = imagesx($source);
$imageY = imagesy($source);
if($width==0)
$maxwidth=$imageX;
else
$maxwidth=$width;
if($imageX>$maxwidth)
{
$thumbX = $maxwidth;
$thumbY = (int)(($thumbX*$imageY) / $imageX );
$dest = imagecreatetruecolor($thumbX, $thumbY);
if(!imagecopyresampled ($dest, $source, 0, 0, 0, 0, $thumbX, $thumbY, $imageX, $imageY))
{
echo "Warning : imagecopyresampled from $src failed in function copy_and_resize<BR>";
return false;
}
}
if(!imagejpeg($dest,$dest_file,$quality))
{
echo "Warning : creation of jpg from $src failed in function copy_and_resize<BR>";
return false;
}
return true;
} |
Partager