Donny van V
Donny van V

Reputation: 961

Cut corners in image PHP

Im working with Intervention Image to make a frame. Now im stuck on a part to cut off the edges. I need 4 of those images to make them fit as a frame. I know i can use the Intervention Image library to rotate the image, but i have no clue to cut those corners. Anyone has a idea how to achieve this?

Original:

Result:

Upvotes: 0

Views: 320

Answers (1)

Taha Paksu
Taha Paksu

Reputation: 15616

You need to create two polygons and fill them with transparent colors.

http://image.intervention.io/api/polygon

An example:

$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

Upvotes: 2

Related Questions