我有一个我正在处理的水印脚本,结果在PNG和JPG图像上很好但是gif图像,不太好.我正在使用PHP和GD
您可以在下面看到水印质量的差异.
有谁知道如何改善这个?
对于我正在使用的gif版本
$image = imagecreatefromgif($source_file);
imagecopymerge($image, $watermark, $x, $y, 0, 0, $water_width, $water_height, 65);
imagegif($image, $source_file);
Run Code Online (Sandbox Code Playgroud)
gif image =质量差的 gif图片http://img2.pict.com/fd/46/00/1471179/0/gif.gif
jpg图片=好的 jpg图片http://img2.pict.com/82/a1/5a/1471181/0/jpg.jpg
GIF图像具有固定的调色板,最多可包含256种颜色.这里的问题可能是插入的图像使用目标图像中不可用的颜色.
我从未尝试过这个,但它可能值得一试.您可以尝试首先将gif图像转换为真彩色图像,然后进行水印,然后将其转换回gif.
$image = imagecreatefromgif($source_file);
// create a true color image of the same size
$image2 = imagecreatetruecolor(imagesx($image), imagesy($image));
// copy the original gif image on to the true color image
imagecopy($image2, $image, 0, 0, 0, 0, imagesx($image), imagesy($image));
// copy the watermark onto the new true color image
imagecopymerge($image2, $watermark, $x, $y, 0, 0, $water_width, $water_height, 65);
// write the new image to disk
imagegif($image2, $source_file);
Run Code Online (Sandbox Code Playgroud)
试一试,看看它是否有所作为.
还有一些可用的调色板操作功能可能会有所帮助:
我不确定你会如何应用它们,但我猜你可以采取一些措施来改善结果.