【问题标题】:Saved images are sometimes completely black保存的图像有时是全黑的
【发布时间】:2019-11-12 10:00:46
【问题描述】:

对于一个网站,我从链接中保存产品图片,这通常可以正常工作。然而,保存的一些图片是完全黑色的,而来自同一来源的大多数其他图片都很好。它们都有 .jpg 扩展名,我不明白正常图像和全黑图像之间的区别。

我用来保存图像的代码:

$source = "http://blablasomething";
$destination = "/somefolder/images";

$imagesize = getimagesize($source);
$orgwidth = $imagesize[0];
$orgheight = $imagesize[1];
$ratio = $orgwidth / $orgheight;

if ($orgwidth > 420) 
{
  $newwidth = 420;
  $newheight = $nw / $ratio;
}
else 
{
  $newwidth = $orgwidth;
  $newheight = $orgheight;
}

$imghandle = imagecreatefromjpeg($source);
$newimage = imagecreatetruecolor($newwidth,$newheight);

imagecopyresampled($newimage,$imghandle,0,0,0,0,$newwidth,$newheight,$orgwidth,$orgheight);     
imagejpeg($newimage,$destination,75);

imagedestroy($newimage);
imagedestroy($imghandle);

我阅读了很多关于类似问题的信息并尝试了很多解决方案,但我无法解决它。希望这里的任何人都可能有线索。

【问题讨论】:

  • 也许更好地依赖 Imagick?
  • 不知道 Imagick,但我会看看,谢谢。
  • Imagick 必须安装在服务器上吗?因为不幸的是我没有专用服务器。我不能只包含 php 类吗?
  • 哦,是的。任何 PHP 图像处理都必须安装在服务器上。

标签: php image save


【解决方案1】:

现在使用 Imagick,黑色的图像现在都很好。感谢您的建议!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多