Skip to content

Default image when filter fails #1622

@redflo

Description

@redflo

Probably this is already possible, but i did not find it in documentation.
Problem:
Users can upload data: images, PDF documents, videos.
After upload, i try to show a thumbnail of the image. This works well for images and PDF files (most of the time), but not for videos.
I tried to set a "default_image" in the filter, but this does not help. My guess is, that default_image only works if the file is not found, but when the image processor cannot generate a image - what then?
default_image parameter is not documented at all. So just guessing here!

Here is my config:

liip_imagine:
    twig:
        mode: "lazy"
    # valid drivers options include "gd" or "gmagick" or "imagick"
    driver: "imagick"
    # configure data loaders
    loaders:
    #    sql_binary_data_loader:
       uploads:
           filesystem:
               data-root: '%app.upload-dir%'
               allow_unresolvable_data_roots: true
    #    chain:
    #        chain:
    #            loaders:
    #                - sql
    #                - uploads
    resolvers:
        upload_thumbs:
            web_path: ~
    # configure custom data loader as default
    data_loader: sql_binary_data_loader
    # configure cache resolvers
    cache: sql_binary_cache
    # your filter sets are defined here
    filter_sets:
        # the name of the "filter set"
        sql_thumb:
            # adjust the image quality to 75%
            quality: 75
            # generate jpeg
            format: jpeg
            # list of transformations to apply (the "filters")
            filters:
                thumbnail: 
                    size: [120, 120]
                    mode: inset
                    allow_upscale: true
                background:
                    color: '#ffffff'
        upload_thumb:
            default_image: "images/thumbnail-dummy.png"
            data_loader: uploads
            cache: upload_thumbs
            # adjust the image quality to 75%
            quality: 75
            # generate jpeg
            format: jpeg
            # list of transformations to apply (the "filters")
            filters:
                thumbnail: 
                    size: [120, 120]
                    mode: inset
                    allow_upscale: true
                background:
                    color: '#ffffff'

The sql loader and cache things just put the images in sql - not my intention, it was a requirement - dont ask.

In Twig (live component):

<img alt="{% trans %}Preview not available{% endtrans %}" src="{{ uploadedFilenames[key]['newFilename'] | imagine_filter('upload_thumb') }}">

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions