admin管理员组文章数量:1026125
<?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
<?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
本文标签: laravelCall to undefined method InterventionImageEncodedImagegetRealPath()Stack Overflow
版权声明:本文标题:laravel - Call to undefined method InterventionImageEncodedImage::getRealPath() - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745624668a2159789.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论