ubuntu php imagecreatefrompng,imagecreatefrompng()使背景变成黑色而不是透明?

操作顺序很重要。对于.gif图像,我发现我需要首先复制调整大小的图像,然后将黑色背景指定为透明背景。对于PNG,我在下面的代码中调整了图像的大小,并保留了透明背景。

而且,这段代码对我有用...

$resized_image = imagecreatetruecolor($target_width, $target_height);

switch ( $asset->a_mime_type )

{

case 'image/jpeg':

imagecopyresampled($resized_image, $source, 0, 0, 0, 0, $target_width, $target_height, $asset->a_image_width, $asset->a_image_height);

$r = imagejpeg($resized_image,$file_name);

break;

case 'image/png':

imagealphablending($resized_image, FALSE);

imagesavealpha($resized_image, TRUE);

imagecopyresampled($resized_image, $source, 0, 0, 0, 0, $target_width, $target_height, $asset->a_image_width, $asset->a_image_height);

$r = @imagepng($resized_image,$file_name);

break;

case 'image/gif':

imagecopyresampled($resized_image, $source, 0, 0, 0, 0, $target_width, $target_height, $asset->a_image_width, $asset->a_image_height);

$background = imagecolorallocate($resized_image, 0, 0, 0);

imagecolortransparent($resized_image, $background);

$r = @imagegif($resized_image,$file_name);

break;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值