Symfony2: Amazon S3 retrieve image and mofidy using Imagine

420 views Asked by At

I'm using amazon s3 to store my images. For now I've got 3 different folders - temporary one to not accepted pictures, one for accepted and one for watermarked one.

When photo is being accepted it is copied to accepted and watermarked folders and deleted form temporary one.

The problem is with watermarked folder because I need to add watermark. During work in progress I've mocked method that is adding watermark like this:

    protected function addWatermark($product)
{
    $filterName = 'watermark';

    $this->imagineFilterManager->getFilter($filterName)
            ->apply($this->imagine->open($product->getFilePath()))
            ->save($path, array('format' => "png"));
}

and it was pretty fine. But the problem is - mock was working on uploaded file, and FilePath was temporary file path to image.

Now I need to retrieve image from amazon s3, pass it to imagineFilterManager and save back at amazon s3 location. The problem is with retrieving photo.

I tried like this: read method:

    public function read($path)
{
    return $this->fileSystem->read($path);
}

    protected function addWatermark($product)
{
    var_dump('addWatermark');

    $filterName = 'watermark';
    $path = $this->getShopPicturePath($product);
    $file = $this->staticContentAdapter->read($path);
    $file = imagecreatefromstring($file);

    $this->imagineFilterManager->getFilter($filterName)
            ->apply($this->imagine->open($file))
            ->save($path, array('format' => "png"));
    var_dump('filtered');exit;
}

but after this $this-imagine-open() returns

File Resource id #141 doesn't exist

The strange thing form me is that it is was possible for me to save image file on s3 using only path:

            ->save($path, array('format' => "png"));

but it is not possible to open file using only path:

            ->apply($this->imagine->open($file->getFilePath()))

It throws exceptions

File watermarked/asd_asd.png doesn't exist.

0

There are 0 answers