Laravel上的水印

问题描述 投票:0回答:1

我想知道您是否能再次帮助我。我无法在个人资料图片上创建水印/在水印上放水印。

到现在为止我有:

WaterMarkController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Image;

class WaterMarkController extends Controller
{
    public function imageWatermark()
    {
        Image::make(public_path('storage/images/background.jpg'));

        /* insert watermark at bottom-right corner with 10px offset */
        $img->insert(public_path('storage/images/watermark.png'), 'bottom-right', 10, 10);
        $img->encode('png');

        $img->save(public_path('storage/images/new-image.png'));

        $type = 'png';
        $new_image = 'data:image/' . $type . ';base64,' . base64_encode($img);

        return view('show_watermark', compact('new_image'));
    }

    public function textWatermark()
    {
        Image::make(public_path('storage/images/background.jpg'));

        $img->text('MyNotePaper', 710, 370, function ($font) {
            $font->file(public_path('font/amandasignature.ttf'));
            $font->size(30);
            $font->color('#f4d442');
            $font->align('center');
            $font->valign('top');
            $font->angle(0);
        });

        $img->save(public_path('storage/images/new-image.png'));

        $img->encode('png');
        $type = 'png';
        $new_image = 'data:image/' . $type . ';base64,' . base64_encode($img);

        return view('show_watermark', compact('new_image'));
    }

}

文件-show_watermark.blade.php:

<!doctype html>
<html lang="en">
<head>
    <title>Laravel Add Watermark on Images</title>
</head>
<body style="margin-top: 40px; text-align: center;">

<h1>Laravel Add Watermark</h1>

<img src="{{$new_image}}" alt="Watermark">

</body>
</html>

和路线:

Route::get('watermark-image', 'WaterMarkController@imageWatermark');
Route::get('watermark-text', 'WaterMarkController@textWatermark');

还应该做什么?因为我遇到了错误:

Intervention \ Image \ Exception \ NotReadableException图片来源不可读

我如何使其可读?而且在代码的任何地方,我都没有显示我想要水印的图像的路径(我已经为项目创建了自己的徽标,并且想使用它),如何显示它的路径?并将其放在个人资料图片的同一位置还是放在另一个文件夹中?

预先感谢!

php laravel photo watermark
1个回答
0
投票

我不知道您会怎么做,也许如果您使用Linux,可能需要向公用文件夹添加权限,因为在Windows上,我使用您的代码创建了一个项目,并且工作正常,请确保文件位于正确的文件夹中] >

public function imageWatermark()
    {
        $img = Image::make(public_path('images/background.jpg'));

        /* insert watermark at bottom-right corner with 10px offset */
        $img->insert(public_path('images/logo-dateado-blanco.png'), 'bottom-right', 10, 10);
        $img->encode('png');

        $img->save(public_path('images/new-image.png'));

        $type = 'png';
        $new_image = 'data:image/' . $type . ';base64,' . base64_encode($img);

        return view('show_watermark', compact('new_image'));
    }

enter image description here

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.