最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

laravel - Call to undefined method InterventionImageEncodedImage::getRealPath() - Stack Overflow

matteradmin6PV0评论
<?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

Post a comment

comment list (0)

  1. No comments so far