douyuan3842 2019-03-16 23:08
浏览 29

上传,重新采样和复制图像脚本正在改变图像的颜色

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.

Original image

Image after upload

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题