Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version

GridFS Loader

1.0 version
Maintained

GridFS Loader

The GridFSLoader allows you to load your images from MongoDB GridFS.

Configuration

1
2
3
4
5
6
7
8
# app/config/config.yml

liip_imagine:
    filter_sets:
        my_special_style:
            data_loader: grid_fs
            filters:
                my_custom_filter: { }

Define a service for the loader:

  • YAML
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    # app/config/services.yml
    
    services:
        liip_imagine.binary.loader.grid_fs:
            class: Liip\ImagineBundle\Binary\Loader\GridFSLoader
            arguments:
                - "@doctrine.odm.mongodb.document_manager"
                - Application\ImageBundle\Document\Image
            tags:
                - { name: "liip_imagine.binary.loader", loader: grid_fs }
    
  • XML
    1
    2
    3
    4
    5
    6
    7
    <!-- app/config/services.xml -->
    
    <service id="liip_imagine.binary.loader.grid_fs" class="Liip\ImagineBundle\Binary\Loader\GridFSLoader">
        <tag name="liip_imagine.binary.loader" loader="grid_fs" />
        <argument type="service" id="doctrine.odm.mongodb.document_manager" />
        <argument>Application\ImageBundle\Document\Image</argument>
    </service>
    

Usage

Reference the image by its id when piping to the template helper:

  • Twig
    1
    <img src="{{ image.id | imagine_filter('my_thumb') }}" />
    
  • PHP
    1
    <img src="<?php echo $this['imagine']->filter($image->getId(), 'my_thumb') ?>" />
    

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.