结果:http://i.stack.imgur.com/p1kVz.png
我正在尝试将PNG复制到另一个PNG,但我不知道它们为什么以这种方式返回
<?php // File and new size
$filename = 'watermark.png';
// Get new sizes
list($width, $height) = getimagesize($filename);
// Load
$resim = 'http://www.petrominpng.com.pg/images/logo_big.png';
$ext = end(explode('.', $resim));
if($ext == "jpeg" || $ext == "jpg")
{
$thumb = imagecreatefromjpeg($resim);
}
else if($ext == "png")
{
$thumb = imagecreatefrompng($resim);
}
$sx = imagesx($thumb);
$sy = imagesy($thumb);
if($sx >= $sy)
{
$sxd = $sx/2;
$degisim = $sxd/$width;
/*
echo $sxd." ".$width." ";
echo $sxd-$width." |";
*/
$sxy = $height * $degisim;
/*
echo " $sxy $height | $degisim";
exit();
*/
}
else
{
$sxy = $sy/2;
$degisim = $sxy/$height;
/*
echo $sxd." ".$width." ";
echo $sxd-$width." |";
*/
$sxd = $width * $degisim;
/*
echo " $sxy $height | $degisim";
exit();
*/
}
$source = imagecreatefrompng($filename);
// Resize
imagecopyresized($thumb, $source, $sx/5, $sy/4, 0, 0, $sxd, $sxy, $width, $height);
// Output
header('Content-type: image/png');
imagepng($thumb);
imagedestroy($thumb);
?>你可以看到,我对图像有问题,我怎么才能纠正它呢?
我的水印
http://i.stack.imgur.com/TZFCa.png
发布于 2013-12-09 04:26:09
你的代码运行得很好,看起来基础png图像(不是水印)有问题,因为如果你用另一个PNG尝试代码,它工作得很好,对于jpg,它也工作得很好。
这似乎是因为原始的PNG是一个PNG8,因为当转换为PNG32时,它工作得很好。
发布于 2015-10-06 15:27:41
你可以试试这个。它在我的项目中运行得很好。
$stamp = imagecreatefrompng('watermark.png');
$im = imagecreatefrompng('source.png');
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 1;
$marge_bottom = 1;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// OUTPUT IMAGE:
header("Content-Type: image/png");
imagesavealpha($im, true);
imagepng($im, NULL); 发布于 2013-12-09 04:34:56
水印图片的格式推荐如下之一:
真正的PNG-8 (recommended)
imagecopymerge函数不能正确处理PNG-24图像;因此不建议这样做。
如果您使用Adobe Photoshop创建水印图像,建议您使用具有以下设置的“存储为Web所用格式”命令:
文件格式: PNG-8,非隔行扫描
颜色减少:选择性,256色
抖动:扩散,88%
透明度:启用,遮罩:无
透明度抖动:扩散透明抖动,100%
https://stackoverflow.com/questions/20458245
复制相似问题