Home > Backend Development > PHP Tutorial > 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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:17:16
Original
933 people have browsed it

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 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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template