PHP在PNG图像中添加PNG水印
我使用PHP在PNG图像中添加PNG水印,php,Php,我使用imagecopyresampled()在图像上添加水印,所有这些都适用于JPG或32/24位PNG,但对于8位PNG,我有以下错误图像: 我怎样才能解决这个问题 我的代码 $tempFile = $_FILES['upload']['tmp_name']; list($width, $height) = getimagesize($tempFile); $new_canvas = imagecreatefrompng($tempFile); // blending the imag
imagecopyresampled()
在图像上添加水印,所有这些都适用于JPG或32/24位PNG,但对于8位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 ImageAlphabling,但在创建PNG图像(如水印)时,结果是一样的
$image = imagecreatefrompng($file_src);
imagealphablending($image, true); // setting alpha blending on
imagesavealpha($image, true); // save alphablending setting (important)
你可以试试我的图像类,它很老了,所以我已经很久没用过了。也许它会起作用。。我喜欢50/50
当然,很高兴我能帮上忙。我一直觉得我对图像做过任何事。