php gd 圆角,使用imagecopyresampled()PHP GD圆角透明_smooth_角

我需要一个脚本,在提供的图像上形成圆角透明角.我找到了一个,它除了一件事之外它的效果很好:应用的角落看起来不平滑.imageantialias()由于PHP在Debian上运行并且重新编译它不是一个选项,因此抛出致命错误.

我发现使这些角落看起来平滑的技巧是调整图像大小imagecopyresampled(),如下所示:

准备图像;

imagecopyresample它到10倍大小;

用特殊颜色画角;

使颜色透明;

将图像缩小到原始大小

但问题出现了:结果图像的角落(在步骤5之后)是平滑的,但不是透明的.当在步骤4之后发送输出图像时(即在减小它的尺寸之前) - 一切都应该如此.

这是负责使角落四舍五入的代码的一部分:

// $dest = image resource

$q=10;

// making everything 10x bigger

$new_width=$width*$q;

$new_height=$height*$q;

$radius=$radius*$q;

$magnified=imagecreatetruecolor($new_width, $new_height);

imagecopyresampled($magnified, $dest, 0,0, 0,0, $new_width,$new_height, ($new_width/$q),($new_height/$q));

// picking the unique colour

$found = false;

while($found == false) {

$r = rand(0, 255);

$g = rand(0, 255);

$b = rand(0, 255);

if(imagecolorexact($magnified, $r, $g, $b) != (-1)) {

$found = true;

}

}

$colorcode = imagecolorallocate($magnified, $r, $g, $b);

// drawing corners

imagearc($magnified, $radius-1, $radius-1, $radius*2, $radius*2, 180, 270, $colorcode);

imagefilltoborder($magnified, 0, 0, $colorcode, $colorcode);

imagearc($magnified, $new_width-$radius, $radius-1, $radius*2, $radius*2, 270, 0, $colorcode);

imagefilltoborder($magnified, $new_width-1, 0, $colorcode, $colorcode);

imagearc($magnified, $radius-1, $new_height-$radius, $radius*2, $radius*2, 90, 180, $colorcode);

imagefilltoborder($magnified, 0, $new_height-1, $colorcode, $colorcode);

imagearc($magnified, $new_width-$radius, $new_height-$radius, $radius*2, $radius*2, 0, 90, $colorcode);

imagefilltoborder($magnified, $new_width-1, $new_height-1, $colorcode, $colorcode);

// making the unique colour transparent

imagecolortransparent($magnified, $colorcode);

// scaling down the enlarged image to it's original size

// expecting corners to remain transparent

imagecopyresampled($dest, $magnified, 0,0, 0,0, ($new_width/$q),($new_height/$q), $new_width,$new_height);

// but they're not

// sending $magnified to output for testing purposes

$dest=$magnified;

// outputting $dest as image/png

因此,您可以看到,当放大的图像被图像复制到其原始大小时,会出现问题.透明的角落充满了$colorcode颜色.我一直在玩,imagesavealpha()并imagealphablending()按照建议,但没有结果.

请帮我完成这项工作.

PS这可能很有用:当将大型PNG上传到imgur.com时,它已将其转换为JPG,因为您可以看到所有角落都填充了非常恢复的$ colorcode.

PS希望我不会因过度使用"放大"这个词而被禁止:)

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值