Home  >  Article  >  Backend Development  >  Solution to PHP scaling GIF and PNG images with transparent background turning into black_PHP Tutorial

Solution to PHP scaling GIF and PNG images with transparent background turning into black_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:17:16799browse

Solution to how PHP scales the transparent background of gif and png images into black

I need to scale some gif images at work and then go to Imagecopymerge, but I found out after using imagecreatetruecolor and imagecopyresampled The background image is wrong. The originally transparent background image turned into black. Later I found that some modifications can be done:

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);

1 2

3

4

5

$img = imagecreatetruecolor(200, 200); //2. Coloring $color=imagecolorallocate($img,255,255,255); //3. Set transparency imagecolortransparent($img,$color); imagefill($img,0,0,$color);
Then imagecopyresampled and Imagecopymerge will be no problem http://www.bkjia.com/PHPjc/894052.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/894052.htmlTechArticleSolution to how php scales gif and png images with transparent backgrounds turning into black. At work, you need to scale some gif images and then go Imagecopymerge, but found that imagecreatetruecolor and imagecopyresa were used...
Statement:
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