使用 CodeIgniter 图像库调整图像大小 canvas - 如何保持透明度

Resize image canvas with CodeIgniter Image Library - how to preserve transparency

我正在尝试通过在其周围添加透明度来调整图像 canvas 的大小(如在 Photoshop 中一样)。不知何故添加的部分图像总是黑色的。

if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor'))
{
     $create = 'imagecreatetruecolor';
     $copy = 'imagecopyresampled';
}
else
{
     $create = 'imagecreate';
     $copy    = 'imagecopyresized';
}

$dst_img = $create($this->width, $this->height);

if ($this->image_type == 3) // png we can actually preserve transparency
{
    //teorethicaly image should be transparent?
    $trans_colour = imagecolorallocatealpha($dst_img, 0, 0 ,0, 127); 
    imagefill($dst_img, 0, 0, $trans_colour);
    imagealphablending($dst_img, FALSE);
    imagesavealpha($dst_img, TRUE);
}

$copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height);

如果我删除 $copy 并只保存新图像,它是透明的,但如果我合并两个图像,背景总是黑色的:

在那种情况下我怎样才能有透明背景?

提前致谢!

http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/ http://www.phpfreaks.com/forums/index.php?topic=232090.0如何在使用 Perl 和 GD 调整 PNG 大小时保持透明度。