How to compress a jpeg (qualitysetting) before saving it to the server?
| From: | Andy | Date: | Fri, 04 Jan 2002 13:48:31 +0000 |
| Subject: | How to compress a jpeg (qualitysetting) before saving it to the server? | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-15382@lists.php.net to get a copy of this message | ||
Hi there,
I am uploading jpegs in my app. How can I control the compression setting
before saving?
Currently my code looks like:
########################################################################
$inputImg = ImageCreateFromJPEG($image);
# old size
$srcX = imagesx($inputImg);
$srcY = imagesy($inputImg);
if ($same == true){ // Image must have the given size. Empty parts are
filled black.
# new size
$ratio = ($srcY / $dstY);
$dstX = ($srcX / $ratio);
$outputImg = ImageCreateTrueColor($maxX, $dstY);
imagefill($outputImg, 0, 0, ImageColorAllocate($outputImg, 0, 0,0));
imagecopyresampled($outputImg, $inputImg, (($maxX - $dstX) / 2),0,0,0,
$dstX, $dstY, $srcX, $srcY);
}
else{ // Image has a y ratio size. Results in not all images same y size.
# new size
$ratio = ($srcX / $maxX);
$dstY = ($srcY / $ratio);
$outputImg = ImageCreateTrueColor($maxX, $dstY);
imagefill($outputImg, 0, 0, ImageColorAllocate($outputImg, 0, 0,0));
imagecopyresampled($outputImg, $inputImg, 0,0,0,0, $maxX, $dstY, $srcX,
$srcY);
}
# save file
imagejpeg($outputImg, $path.$name.".jpg");
########################################################################
Thanx for any help.
Cheers Andy