I made an image cropping and resizing script using PHP and JavaScript. After the user selects their coordinates, the script uploads, resamples, and copies the image with this script. They are both JPEG images.
$maxWidth=$maximumWidth;
$maxHeight=$maximumHeight;
list($width, $height)=getimagesize($f['img']['tmp_name']);
$source = imagecreatefromstring(file_get_contents($f['img']['tmp_name']));
$destination = imagecreatetruecolor($maxWidth, $maxHeight);
// COORDINATES
if(isset($p['x']) && isset($p['y']) && isset($p['w']) && isset($p['h'])){
$x=$p['x'];
$y=$p['y'];
$target_width=$p['w'];
$target_height=$p['h'];
}
else{
if($width>$height){
$center=$width/2;
$halfbox=$height/2;
$x=$center-$halfbox;
$y=0;
$target_width=$height;
$target_height=$height;
}
if($height>=$width){
$center=$height/2;
$halfbox=$width/2;
$x=0;
$y=$center-$halfbox;
$target_width=$width;
$target_height=$width;
}
}
// END COORDINATES
imagecopyresampled($destination, $source, 0, 0, $x, $y, $maxWidth, $maxHeight, $target_width, $target_height);
imagedestroy($source);
imagejpeg($destination, $_SERVER['DOCUMENT_ROOT'].$path.'.jpg', 100);
imagedestroy($destination);
However, the final image appears to lose a lot of color and saturation.
I hope someone can point me in the right direction to figure out why the color is changing and how to fix it. I've been searching here and on other websites for a few days now with no luck. Thank you.