# Named transforms

Named transforms is a new concept in Imager X. It's a way to manage your transforms from a central location, and is required for some of the new features in Imager X, like automatic generation of transforms and transforms in GraphQL.

You can configure your named transforms by creating a config file in your config folder named imager-x-transforms.php, and add transforms as needed. The following example defines two transforms, one with the handle 'heroImage' and one with handle 'listThumbnail'.

<?php

return [
    'heroImage' => [
        'transforms' => [
            ['width' => 600],
            ['width' => 1800],
        ],
        'defaults' => [
            'ratio' => 16/9,
            'jpegQuality' => 80
        ],
        'configOverrides' => [
            'fillTransforms' => true,
            'fillInterval' => 300,
        ]
    ],
    'listThumbnail' => [
        'transforms' => [
            ['width' => 200],
            ['width' => 400],
            ['width' => 600],
        ],
        'defaults' => [
            'ratio' => 4/3,
            'format' => 'jpg'
        ]
    ]
];

You can use these transforms in your templates by passing in the transform handle instead of a transform object:

{% set transforms = craft.imagerx.transformImage(image, 'heroImage') %}

For transform attributes that are dynamic, you can supply a function that will be processed before the transform is used. The function gets the image value that was passed to the transform method as a parameter:

return [
    'articleImage' => [
        'transforms' => [
            ['width' => 600],
            ['width' => 800],
            ['width' => 1000],
            ['width' => 1200],
        ],
        'defaults' => [
            'ratio' => static function ($image) {
                if ($image instanceof \craft\elements\Asset) {
                    if ($image->getWidth() / $image->getHeight() > 1) {
                        return 16/9;
                    } 
                    return 2/3;
                }
                return 16/9;
            },
            'jpegQuality' => 70
        ]
    ],
];

TIP

It's a good idea to code defensively in config files, since any edge case errors will be extra hard to catch if it occurs, for instance, during automatic generation inside an event handler.