在图像中切角PHP
问题描述:
我正在使用Intervention Image来制作一个框架。现在我卡在一个部分切断边缘。我需要这些图像中的4个以使它们适合作为框架。我知道我可以使用干预图像库来旋转图像,但我不知道切割这些角落。任何人都有一个想法如何实现这一点?在图像中切角PHP
原文:
结果:
答
您需要创建两个多边形,并用透明的颜色填充。
http://image.intervention.io/api/polygon
一个例子:
$img = Image::make('foo/bar/baz.jpg')->encode('png');
$w = $img->width();
$h = $img->height();
$points = [0,0,$width,0,$width,$width,0,0];
$img->polygon($points, function($d) {
$d->background("transparent");
});
$points = [0,$height,$width,$height,$width,$height-$width,0,$height];
$img->polygon($points, function($d) {
$d->background("transparent");
});
$img->save('foo/bar/baz_cut.png'); // jpg won't have transparency
我使用的背景( '透明'),但是然后我接收到的错误:无法读取色(透明)。任何想法可能是什么? –
然后您可以使用'rgba(0,0,0,0)'来获得该透明度。 –
是的,我见过那个伴侣,谢谢!有那个伎俩。你是我的救世主! –