2

I have been researching for hours and can't get a handle on how to do some effective image manipulation within Symfony2. The Liip Imagine bundle seems to be the way to go but I can't seem to get it to work properly for me in development.

What I want:

  • On upload create image sizes, preferably % based (I would rather do this that wait for a request for the image because if it is huge I don't want that person to be the one waiting while it caches)
  • Create a watermark on the image
  • retrieve meta from the image, sizing, DI etc.

I have looked at the following:

Config:

liip_imagine:
resolvers:
   default:
      web_path: ~

filter_sets:
    cache: ~
    my_thumb:
        quality: 75
        filters:
            thumbnail: { size: [120, 90], mode: outbound }

Attempted Twig:

img src="{{ asset(file.webPath) | imagine_filter('my_thumb') }}"

EDIT!!

So I used the following code to attempt to do it on upload from the above post that I pasted in:

   private function writeThumbnail($document, $filter) {
    $path = $document->getWebPath();                                // domain relative path to full sized image
    $tpath = $document->getRootDir().$document->getThumbPath();     // absolute path of saved thumbnail

    $container = $this->container;                                  // the DI container
    $dataManager = $container->get('liip_imagine.data.manager');    // the data manager service
    $filterManager = $container->get('liip_imagine.filter.manager');// the filter manager service

    $image = $dataManager->find($filter, $path);                    // find the image and determine its type
    $response = $filterManager->get($this->getRequest(), $filter, $image, $path); // run the filter 
    $thumb = $response->getContent();                               // get the image from the response

    $f = fopen($tpath, 'w');                                        // create thumbnail file
    fwrite($f, $thumb);                                             // write the thumbnail
    fclose($f);                                                     // close the file
}

And now this line $image = $dataManager->find($filter, $path) is throwing the following error:

The mime type of image uploads/files/pic_05052015_827_c6d4b.jpg must be image/xxx got inode/x-empty.

I'm a little lost with some of this deep image stuff.

Community
  • 1
  • 1
Adam
  • 675
  • 5
  • 25

0 Answers0