Creating custom thumbnails types

Hello everyone,

I’d like to create custom thumbnail types to have access to a wider range of pre-generated image sizes.

Something like :

        'types' => [
            'extraLarge' => ['constraint' => 1600],
            'large' => ['constraint' => 800],
            'medium' => ['constraint' => 200],
            'small' => ['constraint' => 100],
            'extraSmall' => ['constraint' => 50],
            'square' => ['constraint' => 200],
        ],

Is there a way to integrate such changes into my site API and regenerate the thumbnails accordingly?

Thanks for your help

You can add extra types there… when you add them you have to specify more than when you’re just changing the size of an existing one though:

'extraLarge' => ['constraint' => 1600, 'strategy' => 'default', 'options' => []],

The API will automatically include extra derivatives added here. As for regenerating them, I know there are modules for that, like Create Missing Thumbnails, though I’m not 100% certain they support custom thumbnail types like these… my first guess would be that they do.

1 Like

Its works thanks a lot !

I wasn’t able to regenerate them with Create Missing Thumbnails, but with Easy Admin module.

Edit : I find some minimal documentation about theses arguments here Configuration Reference - Omeka S Developer Documentation but no examples or nothing explicit about the fact it can be customized, types are just mentioned as '(large, medium, and square types)".

Thanks again !

Hi @Maxime ,

I agree that perhaps there could be a little more explanation for the thumbnail configuration, especially around the available options. These are specific to each thumbnailer, so the ImageMagick thumbnailer will have different options than the GD thumbnailer, and if you were to write your own custom thumbnailer, you could use the options key to add configurable options.

I just wanted to add a little context in case you’re wondering why more array keys are needed for the additional sizes. In Omeka S, there is a default application config file and your local config file. The local config file gets merged with the application config file. The full thumbnails key in the application config file looks like this:

'thumbnails' => [
        'types' => [
            'large' => [
                'strategy' => 'default',
                'constraint' => 800,
                'options' => [],
            ],
            'medium' => [
                'strategy' => 'default',
                'constraint' => 400,
                'options' => [],
            ],
            'square' => [
                'strategy' => 'square',
                'constraint' => 200,
                'options' => [
                    'gravity' => 'center',
                ],
            ],
        ],
        'fallbacks' => [
            'default' => ['thumbnails/default.png', 'Omeka'],
            'fallbacks' => [
                'image' => ['thumbnails/image.png', 'Omeka'],
                'video' => ['thumbnails/video.png', 'Omeka'],
                'audio' => ['thumbnails/audio.png', 'Omeka'],
            ],
        ],
        'thumbnailer_options' => [
            'imagemagick_dir' => null,
            'page' => 0,
        ],
    ],

Since the local config is merged, the only key included for each type is the constraint. Presumably, this is because this is the most common change users will make. However, you could modify the large, medium, and square types in your local config to override the strategy and options as well. As John mentioned, if you add your own types, you must include the full configuration since you’re not just overriding an existing configuration key.

1 Like