【问题标题】:PHP Merge ImagesPHP 合并图像
【发布时间】:2015-01-06 05:22:52
【问题描述】:

我合并了两个图像。第一张图片总是白色的,扩展名是PNG,大小是1200px X 628px。第二张图片的大小为 1000 像素 X 495 像素。但是当我合并这些图像时,白色图像会转换为黑色图像。并显示第二张图像的背景是黑色的。 请帮助我如何解决此问题并将黑色图像更改为白色图像。

【问题讨论】:

  • 对不起,请附上你得到的和你想要的输出。
  • 哪个库正在使用GD2ImageMagick 也显示您的代码??
  • 请同时显示您当前的代码,否则我们无法为您提供帮助
  • @ShineDezign 你需要为图像做水????

标签: php image


【解决方案1】:

在您的代码中添加以下行,您的问题应该得到解决,

imagealphablending($new_image, false);
imagesavealpha($new_image, true);
$transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127);
imagefilledrectangle($new_image, 0, 0, $width, $height, $transparent);

仅供参考,调整图像大小的完整源代码,

function resize($width,$height) {
      $new_image = imagecreatetruecolor($width, $height);
      if ($this->image_type == IMAGETYPE_PNG){
        imagealphablending($new_image, false);
        imagesavealpha($new_image, true);
        $transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127);
        imagefilledrectangle($new_image, 0, 0, $width, $height, $transparent);
      }
      imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
      $this->image = $new_image;
   }      

【讨论】:

  • 对不起,Girish 我可能不会回答你的问题,但上面代码中使用的函数仅适用于 GD。 php.net/manual/en/ref.image.php
  • 你的答案是正确的,但是op 没有显示有问题的代码也使用了哪个库,如果他使用ImageMagick 那么这段代码可以工作吗?
  • 不,这仅适用于 GD,不适用于 ImageMagick。
猜你喜欢
  • 2011-07-28
  • 2019-03-12
  • 1970-01-01
  • 1970-01-01
  • 2011-04-22
  • 2019-08-01
  • 2012-10-10
  • 2012-02-10
  • 2011-05-21
相关资源
最近更新 更多