我在我的项目图像包Intervention-Image中使用 将水印添加到服务中的每个上载图像中,我使用代码打击,但哈希处理出错 哈希仅每次给我watermark.png的哈希
Route::post('/upload_image',function (Request $request)
{
$real_path = Image::make($request->file('image')->getRealPath());
$img_for_hash = Image::make($real_path);
$img = Image::make($real_path);
// calculate md5 hash of encoded image
$hash = md5($img_for_hash->__toString());
// use hash as a name
$path = "images/{$hash }.jpg";
$watermark = Image::make(public_path('watermark.png'));
$img->insert($watermark, 'bottom-right', 10, 10);
// save it locally to ~/public/images/{$hash}.jpg
$img->save(public_path($path));
return $hash ;
})->name('upload_image');
查看
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Upload Image</title>
</head>
<body>
<form action="{{ route('upload_image') }}" method="post" enctype="multipart/form-data" >
@csrf
<input type="file" name="image">
<button type="submit"> upload </button>
</form>
</body>
</html>
任何解决方案都使用回叫还是因为水印?我不知道为什么这段代码每次都会给我同样的哈希值。