Home > Backend Development > PHP Tutorial > php缩放gif和png图透明背景变成黑色的解决方法_PHP

php缩放gif和png图透明背景变成黑色的解决方法_PHP

WBOY
Release: 2016-05-31 19:29:30
Original
950 people have browsed it

工作中需要缩放一些gif图然后在去Imagecopymerge,可是发现使用了imagecreatetruecolor和imagecopyresampled后发现背景图不对,本来透明的背景图变成了黑色,后来发现做一些修改才可以:

 $img = imagecreatetruecolor(200, 200); 
//2.上色 
$color=imagecolorallocate($img,255,255,255); 
//3.设置透明 
imagecolortransparent($img,$color); 
imagefill($img,0,0,$color); 

Copy after login

然后再进行imagecopyresampled和Imagecopymerge就没有问题了

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template