PHP 怎么去掉一张图片里的一些颜色,让其变成透明?
用 imagecolortransparent
两个参数 第一个是图片,第二个是匹配的颜色
匹配颜色是 ImageColorAllocate
完整的演示 比如:
imagecolortransparent($image,imagecolorallocate($image,255,255,255));
这样就是把匹配到的白色变为透明
函数介绍:
一些颜色的话用循环 把匹配颜色循环变透明
imagecolortransparent
— 将某个颜色定义为透明色。
语法
int imagecolortransparent ( resource $image [, int $color ] )
imagecolortransparent() 将 image 图像中的透明色设定为 color。image 是 imagecreatetruecolor() 返回的图像标识符,color 是 imagecolorallocate() 返回的颜色标识符。
注意:透明色是图像的一种属性,透明度不是颜色的属性。一旦设定了某个颜色为透明色,图像中之前画为该色的任何区域都成为透明的。
返回新透明色的标识符,如果省略 color 则返回当前透明色的标识符。
注意:透明度仅能通过 imagecopymerge() 和真彩色图像拷贝,不能用 imagecopy() 或调色板图像。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)