使用PHP的GD库中的imagepng()和透明度 [英] imagepng() and transparency in GD library with PHP

查看:605
本文介绍了使用PHP的GD库中的imagepng()和透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中使用函数imagepng()时,如何确保保存的图像带有透明背景?

When using the function imagepng() in PHP, how can I make sure the images that I save are saved with a transparent background?

推荐答案

以下是

Here is an example of the imagecolortransparent function (if it helps):

<?php
// Create a 55x30 image
$im = imagecreatetruecolor(55, 30);
$red = imagecolorallocate($im, 255, 0, 0);
$black = imagecolorallocate($im, 0, 0, 0);

// Make the background transparent
imagecolortransparent($im, $black);

// Draw a red rectangle
imagefilledrectangle($im, 4, 4, 50, 25, $red);

// Save the image
imagepng($im, './imagecolortransparent.png');
imagedestroy($im);
?>

这篇关于使用PHP的GD库中的imagepng()和透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆