I need insert some images to another image using intervention image and laravel.
This is my main image:

And these are my images to insert to main image:


And finally this image after insert:

Well, I use this code to make this:
$img = Image::make(asset('images/cover.png' ) )->encode('jpg', 15);
$token = Session::get('_token');
$imgWidth = $img->width();
$imgHeight = $img->height();
$coverImages = Storage::allFiles('public/' . $token . '/cover');
$r1 = Image::make(asset('storage/' . $token . '/cover/r1.png') );
$r2 = Image::make(asset('storage/' . $token . '/cover/r2.png') );
$r1->resize(80, 180, function ($constraint){
$constraint->aspectRatio();
});
$r2->resize(80, 180, function ($constraint){
$constraint->aspectRatio();
});
$img->insert($r1, 'top-left', 190, 175);
$img->insert($r2, 'top-left', 290, 175);
$img->save( public_path("storage/{$token}/111111.png"));
Now I need to round r1.png and r2.png corners to fit main image.
Do you know how can I do this?
Thanks in Advance
NOTE :
Thanks to @Pascal Meunier, but
I need to round
r1.pngcorners by itself, because I have to save rounded image in another place again for some reasons...
I have not try this myself, but it could be done using mask method from the Intervention class. With this you would need another image of a white rounded rectangle with a black background for the mask.
it should work like this:
$img = Image::make(asset('images/cover.png' ) )->encode('jpg', 15);
$token = Session::get('_token');
$imgWidth = $img->width();
$imgHeight = $img->height();
$coverImages = Storage::allFiles('public/' . $token . '/cover');
$r1 = Image::make(asset('storage/' . $token . '/cover/r1.png') );
$r2 = Image::make(asset('storage/' . $token . '/cover/r2.png') );
$r1->resize(80, 180, function ($constraint){
$constraint->aspectRatio();
})->mask('public/mask.png');
$r2->resize(80, 180, function ($constraint){
$constraint->aspectRatio();
})->mask('public/mask.png');
$img->insert($r1, 'top-left', 190, 175);
$img->insert($r2, 'top-left', 290, 175);
$img->save( public_path("storage/{$token}/111111.png"));
I found a way, by using a canvas and inserting r1 and r2 before the main image.
$cover = Image::make('main.png');
$r1 = Image::make('r1.png');
$r2 = Image::make('r2.png');
$r1->resize(80, 180, function ($constraint){
$constraint->aspectRatio();
});
$r2->resize(80, 180, function ($constraint){
$constraint->aspectRatio();
});
$canvas = Image::canvas(746, 738);
$canvas->insert($r1, 'top-left', 190, 175);
$canvas->insert($r2, 'top-left', 290, 175);
$canvas->insert($cover);
$canvas->save('final.png');
The result looks like this.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With