繁体   English   中英

PHP在PNG图像中添加PNG水印

[英]PHP Add PNG watermark in PNG image

我使用imagecopyresampled()在图像上添加水印,使用JPG或32 / 24Bits PNG都可以正常工作,但是使用8bits PNG时,我有此错误图像:

在此处输入图片说明

我该如何解决?

我的密码

$tempFile = $_FILES['upload']['tmp_name'];
list($width, $height) = getimagesize($tempFile);

$new_canvas = imagecreatefrompng($tempFile);

// blending the images together
imagealphablending($new_canvas, true);

// Watermark
$watermark = imagecreatefrompng('watermark.png'); //watermark image
$width_watermark = imagesx($watermark); // 300px
$height_watermark = imagesy($watermark); // 100px

// blending the images together
imagealphablending($watermark, true); 

//calculate size of watermark
$stw = $width / 4;
$sth = $stw / 3;

//calculate center position of watermark image
$watermark_left = ($width / 2) - ($stw / 2); //watermark left
$watermark_bottom = ($height / 2) - ($sth / 2); //watermark bottom

imagecopyresampled($new_canvas, $watermark, $watermark_left, $watermark_bottom, 0, 0, $stw, $sth, $width_watermark, $height_watermark);

我已经尝试过更改为false imagealphableding,但其结果相同

创建PNG图像(如水印)时,应执行此操作

$image = imagecreatefrompng($file_src);
imagealphablending($image, true); // setting alpha blending on
imagesavealpha($image, true); // save alphablending setting (important)

您可以尝试我的图像类,它很老了,所以我没有永远使用它。 也许会工作..即时消息像50/50

https://github.com/ArtisticPhoenix/MISC/tree/master/Image

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM