我试图制作一个图像上传器,除了在透明的gif上面放置水印之外,一切都运行良好。它自我保持透明的gif,但是由于某种原因,放置在gif透明背景上的水印部分会出现红色背景,我很难找到原因。有什么建议吗?
else if ($this->fileType === "image/gif") {
$newFilename = $this->placeholder();
$img = imageCreateFromGif($this->fileTmpName);
imageAlphaBlending($img, true);
imageSaveAlpha($img, true);
if($this->watermarkEnabled === true) {
$this->watermark($img);
}
$newFilename = imageGif($img, $newFilename.".".$this->fileExtension);
}
function watermark($img) {
// creating png image of watermark
$watermark = imagecreatefrompng($this->watermarkImage);
// getting dimensions of watermark image
$watermarkWidth = imagesx($watermark);
$watermarkHeight = imagesy($watermark);
// placing the watermark 10px from bottom and right
$destX = $this->imageSize[0] - $watermarkWidth - 10;
$destY = $this->imageSize[1] - $watermarkHeight - 10;
// creating a cut resource
$cut = imagecreatetruecolor($watermarkWidth, $watermarkHeight);
imagefill($cut,0,0,0x7fff0000);
// copying that section of the background to the cut
imagecopy($cut, $img, 0, 0, $destX, $destY, $watermarkWidth, $watermarkHeight);
// placing the watermark now
imagecopy($cut, $watermark, 0, 0, 0, 0, $watermarkWidth, $watermarkHeight);
// merging both of the images
imagecopymerge($img, $cut, $destX, $destY, 0, 0, $watermarkWidth, $watermarkHeight, 100);
imagedestroy($watermark);
}
答案 0 :(得分:0)
我通过将图像从Gif转换为Png然后添加水印来解决这个问题。