[英]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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.