Home > php教程 > php手册 > php缩放gif和png图透明背景变成黑色的解决方法

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

WBOY
Release: 2016-06-13 09:23:58
Original
1019 people have browsed it

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

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

1

2

3

4

5

6

$img = imagecreatetruecolor(200, 200); 

//2.上色 

$color=imagecolorallocate($img,255,255,255); 

//3.设置透明 

imagecolortransparent($img,$color); 

imagefill($img,0,0,$color);

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

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template