<?php
use Intervention\Image\Image;
class WatermarkStrategy
{
/**
*
* @param mixed $fileImage uploaded file
* @return Image
*/
public function snap($fileImage): Image
{
$imageManager = app('ImageManager');
$uploadedFile = $imageManager->read($fileImage);
// apply water mark
$modifiedImage = $this->apply(
$uploadedFile,
['position' => 'top-left', 'opacity' => 100]
);
return $modifiedImage;
}
public function apply(Image $uploadedFile, mixed $value): Image
{
try {
$client = new \GuzzleHttp\Client();
$response = $client->get('s3/watermark.jpg');
$imageContent = $response->getBody()->getContents();
// error was thrown in here cuz intervention image can't read the image from s3,but i need to read that image from s3 and place as watermark
$waterMark = app("ImageManager")->read($imageContent);
return $uploadedFile->place(
$waterMark,
$value['position'],
opacity: $value['opacity']);
} catch (\Exception $e) {
throw new \InvalidArgumentException('Watermark image not found');
}
}
}
Problem
The function throws an error because Intervention Image v3 doesn’t allow creating images from a URI directly. My goal is to retrieve the watermark image from a cloud provider, process it, and place it on the uploaded image.
Question
How can I fetch an image from a cloud URI, process it, and use it as a watermark in Intervention Image v3? Is there an alternative approach or workaround for this limitation?
Tech :framework : Laravel 10, package : image intervention v3 , storage : s3
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745624670a4636734.html
评论列表(0条)