PHP code example of superbig / craft-imagerpretransform

1. Go to this page and download the library: Download superbig/craft-imagerpretransform library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

superbig / craft-imagerpretransform example snippets



return [
    // Toggle pretransforming as needed
    'enabled' => true,
    // This will process each image in a separate job. Perfect in combination with Async Queue.
    'processImagesInJobs' => false,
    // Transforms - these options are passed straight to Imager
    'transforms' => [
        // Global transform, will be applied to all images
        [
            'width' => 1400,
        ],
        // Images source, with handle images
        'images' => [
            [
                'width' => 1400,
            ],
            [
                'width'       => 600,
                'jpegQuality' => 65
            ],
            [
                'width'       => 380,
                'height'      => 380,
                'mode'        => 'crop',
                'position'    => 'center-center',
                'jpegQuality' => 65
            ],

            'defaults' => [

            ],

            'configOverrides' => [
                'resizeFilter'         => 'catrom',
                'instanceReuseEnabled' => true,
            ]
        ],

        'anotherSourceHandle' => [
            [
                'height' => 600
            ]
        ]
    ]
];


return [
    'transforms' => [
        [
            'width' => 1400,
        ],
        [
            'width'       => 600,
            'jpegQuality' => 65
        ],
        [
            'width'       => 380,
            'height'      => 380,
            'mode'        => 'crop',
            'position'    => 'center-center',
            'jpegQuality' => 65
        ],

        'defaults' => [],
        'configOverrides' => []
    ]
];


return [
    'transforms' => [
        [
            'template' => '_imager-pretransform',
        ],
    ]
];

'cacheDuration' => 31536000, // 1 year


return [
    'transforms' => [
        [
            'width'       => 400,
            'height'      => 400,
            'mode'        => 'croponly',
            'position'    => function (Asset $asset) {
                return $asset->getFocalPoint();
            },
        ],
    ]
];