php - 使用干预图像和 laravel 5.4 圆角图像

标签 php image laravel-5 laravel-5.4 intervention

我需要使用 intervention image 和 laravel 将一些图像插入到另一个图像中。

这是我的主图:

main image

这些是我要插入主图像的图像:

r1 image

r2 image

插入后的最后一张图片:

final image sample

好吧,我用这段代码来做这个:

    $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"));

现在我需要将 r1.pngr2.png 的角倒圆以适应 main图片

你知道我该怎么做吗?

提前致谢

注意:

感谢 @Pascal Meunier,但是

I need to round r1.png corners by itself, because I have to save rounded image in another place again for some reasons...

最佳答案

我找到了一种方法,通过使用 canvas 并在 main 图像之前插入 r1r2

$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');

结果如下所示。

enter image description here

关于php - 使用干预图像和 laravel 5.4 圆角图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44587895/

相关文章:

php - 设置外键检查不起作用 Laravel 迁移

javascript - 使用 php 刷新时无法更改事件分页按钮

php - 获取特定类的所有对象

jquery数组图像淡入淡出背景

javascript - 通过<a href ="#myModel"></a>标签传递值(使用html中的链接传递数据值值)?

php - 在 php - mysql 中嵌套 "group by"和 "for (each)"语句

jquery - 在第一个图像元素 jquery 之后添加图像

image - Three.js 从图像导入 svg 路径

php - paginate() 函数抛出异常 - PDOException SQLSTATE[HY093] : Invalid parameter number for in Laravel

php - Laravel 5.2 migration comment on migration 专栏