Search code examples
symfonyimagefilterliipimaginebundle

500 internal server error - IOException: Failed to create media/cache/my_thumb with LiipImagineBundle


I am trying to apply a filter on an image based on LiipImagineBundle.

Here are the steps:

  1. Installation through the composer file by adding this line:

    "liip/imagine-bundle": "1.0.*@dev"

  2. Configuration of the config.yml file by adding these lines:

    liip_imagine:
        resolvers:
        default:
            web_path:  
                web_root: %kernel.root_dir%/../web
                cache_prefix: media/cache
    
    filter_sets:
        cache: ~
        my_thumb:
            quality: 75
            filters:
              thumbnail: { size: [120, 90], mode: outbound }
    
  3. Declaration of the bundle in AppKernel.php:

    new Liip\ImagineBundle\LiipImagineBundle(),
    
  4. Testing the bundle by adding there line the twig file:

    <img src="{{ asset('img/test.jpg') | imagine_filter('my_thumb') }}" />
    

But, no image was displayed. The generated HTML file contains:

<img src="http://localhost/tuto/web/app_dev.php/media/cache/my_thumb/img/test.jpg">

And in the javascript console of the browser, I find this error:

GET http://localhost/tuto/web/app_dev.php/media/cache/my_thumb/img/test.jpg 500 (Internal Server Error)

When I try to open the link (with the 500 Internal Server Error), symfony throws this error:

Failed to create /home/amine/NetBeansProjects/tuto/app/../web/media/cache/my_thumb/img 500 Internal Server Error - IOException

I guess I do not have the permission to create the following folder: /home/amine/NetBeansProjects/tuto/app/../web/media/cache/my_thumb/img. In my point of view, it was expectable since I working on Ubuntu.

To avoid this problem, I directly changed the permissions on the folder web through sudo chmod 777 -R web but the problem is still the same.

Is there any idea?


Solution

  • I thought it is working but it is not! It was loading image from old cache. Forget my last post!

    I think there is a bug in the bundle. I explain:

    Here is my new config of the bundle:

        liip_imagine:
            resolvers:
            default:
                web_path:  
                    web_root: %kernel.root_dir%/../web/img
                    # %kernel.root_dir%/../web/img is the folder where filtered images will be created!
                    cache_prefix: media/cache
                    # media/cache the prefix of folder where the cached images will be created
    
        filter_sets:
            cache: ~
            my_thumb:
                quality: 75
                filters:
                  thumbnail: { size: [120, 90], mode: outbound }
    

    This is the twig part for displaying the image:

    {# This way the filtered image will not be created!#}
    <img src="{{ 'img/test.jpg' | imagine_filter('my_thumb') }}" />
    
    {# That way, the filted images will be created. asset() must be used. #}
    <img src="{{ asset('img/test.jpg' | imagine_filter('my_thumb')) }}" />
    

    The generated link of the image is not correct! In fact, the obtained link is:

    http://localhost/media/cache/my_thumb/img/test.jpg

    The expected correct link is:

    http://localhost/**tuto/web/img**/media/cache/my_thumb/img/test.jpg

    There is a missing part in the tuto/web/img . Is this a bug?

    To avoid that problem, I did this:

    <img src="{{ asset('img/test.jpg' | imagine_filter('my_thumb'))|replace({'media':'tuto/web/img/media'}) }}" />
    

    I guess: playing with twig is not a good solution. I hope we will find a solution to this bug!

    Thanks!