PHP code example of craftyhedge / craft-thumbhash

1. Go to this page and download the library: Download craftyhedge/craft-thumbhash 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/ */

    

craftyhedge / craft-thumbhash example snippets


return [
    // ...
    'renderMethod' => 'bg', // or 'img' or 'picture'
];



return [
    'volumes' => '*',
    // 'autoGenerate' => true,
    // 'renderMethod' => 'bg',
    // 'scriptPosition' => 'head',
    // 'generateDataUrl' => true,
    // 'fetchConcurrency' => 3,
];

return [
    'volumes' => '*',

    // Only generate for assets in these folders
    'ders (applied after  ],
];

return [
    'sources' => [
        'imgix' => [
            'provider' => 'imgix',
            'endpoint' => App::env('IMGIX_DOMAIN'),
            'privateKey'   => App::env('IMGIX_KEY'),
            'signed'    => true,
            'defaultParams' => ['auto' => 'compress,format']
        ],
    ],
    'transformSource' => 'imgix', // <-- the important part :)
];
bash
# All image assets (uses configured volumes setting)
php craft thumbhash/generate

# Specific volume (overrides the configured volumes setting)
php craft thumbhash/generate --volume=images
bash
php craft thumbhash/generate/clear --yes=1

# Clear only stored PNG data URLs, keep thumbhash strings
php craft thumbhash/generate/clear-data-urls --yes=1