本文介绍了用php删除图像背景并保存透明png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想删除在PHP平台上工作的网站上上传的所有图像的白色背景.上载功能已完成,但将其弄乱了.
I want to remove the white background of any image uploaded on the site working on PHP platform. The uploading function is done but messed up with this functionality.
这是我在这里找到的链接:从图像中删除白色背景并使其透明
Here is the link I found here:Remove white background from an image and make it transparent
但这是相反的.我要删除彩色背景,并使其具有透明背景图像.
But this is doing reverse. I want to remove the colored background and make it image with transparent background.
推荐答案
由于只需要单色透明性,所以最简单的方法是用imagecolortransparent()
定义白色.这样的东西(未经测试的代码):
Since you only need single-color transparency, the easiest way is to define white with imagecolortransparent()
. Something like this (untested code):
$img = imagecreatefromstring($your_image); //or whatever loading function you need
$white = imagecolorallocate($img, 255, 255, 255);
imagecolortransparent($img, $white);
imagepng($img, $output_file_name);
这篇关于用php删除图像背景并保存透明png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!