我有使用 GD 用 php 语言编写的缩略图创建类。我想知道当我上传 png 或 gif 透明图像时,我可以在缩略图中添加背景吗?如果可能的话,请指导我如何做。谢谢。
这是 PNG 文件的有效解决方案:
$filePath = ''; //full path to your png, including filename and extension
$savePath = ''; //full path to saved png, including filename and extension
$colorRgb = array('red' => 255, 'green' => 0, 'blue' => 0); //background color
$img = @imagecreatefrompng($filePath);
$width = imagesx($img);
$height = imagesy($img);
//create new image and fill with background color
$backgroundImg = @imagecreatetruecolor($width, $height);
$color = imagecolorallocate($backgroundImg, $colorRgb['red'], $colorRgb['green'], $colorRgb['blue']);
imagefill($backgroundImg, 0, 0, $color);
//copy original image to background
imagecopy($backgroundImg, $img, 0, 0, 0, 0, $width, $height);
//save as png
imagepng($backgroundImg, $savePath, 0);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)