I made an app where the user can upload an image, crop it with jCrop and then it's send to him via email. Everything works as expected, but the php script that creates the image seems to reduce the quality a bit while cropping/resizing. It's not extreme, but I need the same resolution as the image that has been uploaded. I had imagejpg() and changed it with imagepng(), without success. Maybe you can help me. Here's the code:
list($oWidth, $oHeight) = getimagesize($_POST["hiddenSrc"]);
$xPos = $_POST["x1h"];
$yPos = $_POST["y1h"];
$targ_w = $_POST["wh"];
$targ_h = $_POST["hh"];
$jpeg_quality = 9;
$src = $_POST["hiddenSrc"];
if(mime_content_type($src) == "image/jpeg")
{
$img_r = imagecreatefromjpeg($src);
}
else if(mime_content_type($src) == "image/png")
{
$img_r = imagecreatefrompng($src);
}
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$xPos,$yPos,$targ_w,$targ_h,$targ_w,$targ_h);
if(!file_exists('../FOLDER/'.$_SESSION['foldername'].'/PRODUKT'.$_SESSION['productNameCount'].'.png'))
{
imagepng($dst_r,"../FOLDER/".$_SESSION['foldername']."/PRODUKT".$_SESSION['productNameCount'].".png",$jpeg_quality);
}
The rest of the script is just creating the folder and other stuff that is not related with the image
Thank you very much!
The rest is just some functions determinining that the image's not too small, ect.
Here's a before/after comparison:
I know the difference is slight, but it is very visible when the image is printed
I finally figured out the problem.
I transfered the uploaded image to a data-url which reduced the quality. If I directly upload the image file the quality stays the same. (+ I'm using Imagemagick)
But now I'm having trouble with quality loss while resizing the images, but that's another story and another thread ;)
Thanks all