spacecatninja / craft-imager-x

Image transforms, optimizations and manipulations for your Craft CMS site.
Other
26 stars 16 forks source link

No automatic generation for webp images #222

Closed jessedobbelaere closed 1 year ago

jessedobbelaere commented 1 year ago
### I'm submitting a...

Steps to reproduce

  1. Upload 10+ webp images and one JPG image in an entry field
  2. Setup automatic generation and named transforms
  3. Run ./craft resave/entries --element-id XXX to trigger a resave of the entry, or simply hit save from the Craft CMS entry page.
  4. Monitor the queue table or via the CLI or Craft queue manager page. I only see one queue job being added, for the jpg image. The webp images do not trigger.

I have the following generate and named transforms config:

imager-x-generate.php

<?php

use craft\elements\Entry;

return [
    'generateOnlyForLiveElements' => true,
    'elements' => [

        // Shop
        [
            'elementType' => Entry::class,
            'criteria' => [
                'section' => 'catalog'
            ],
            'fields' => ['productImages'],
            'transforms' => [
                'productGalleryPreviewImage',
                'productGalleryPreviewImageWebp',
                'productGalleryPreviewImageAvif',
                'productGalleryFullscreenImage',
            ]
        ],

    ],
];

imager-x-transforms.php

<?php

use craft\elements\Asset;

$defaults = [
    'mode' => 'crop',
    'interlace' => true,
    'effects' => [
        'sharpen' => true,
    ],
    'position' => static function ($image) {
        if (($image instanceof Asset) && $image->hasFocalPoint) {
            return $image->getFocalPoint(true);
        }
        return '50% 50%'; // Default
    }
];

return [

    // Products
    'productGalleryPreviewImage' => [
        'transforms' => [
            ['width' => 500, 'height' => 500, 'mode' => 'letterbox', 'letterbox' => ['color' => '#FFFFFF']],
        ],
        'defaults' => $defaults,
    ],
    'productGalleryPreviewImageWebp' => ['transforms' => 'productGalleryPreviewImage', 'defaults' => ['format' => 'webp']],
    'productGalleryPreviewImageAvif' => ['transforms' => 'productGalleryPreviewImage', 'defaults' => ['format' => 'avif']],
    'productGalleryFullscreenImage' => [
        'transforms' => [['width' => 1920, 'mode' => 'fit']],
        'defaults' => $defaults,
    ],

];

Description

I have a catalog of around 50 products (entries), and each product entry has a bunch of images. To avoid the page hanging for 1-2 minutes, I set up [automatic generation](https://imager-x.spacecat.ninja/usage/generate.html) and named transforms. However, after resaving all entries a bunch of times, I still noticed the page hanging for a few minutes. After debugging I found that either the optimizer kicks in on page load (#219) but after disabling that still did not fix the page load time for a few entries. I found that only the jpg images get added to the queue and automatically transformed, and products with a lot of webp images get transformed only at page load. I can see the custom avif encoder process kicking in during page load using `ps aux`. Anything I might be missing that causes the webp images in the Entry field to be ignored when resaving and scheduling the jobs in the queue? The webp images never end up on the queue. ### Additional info - Imager version & edition: 4.1.13 PRO - Imager transformer: craft - Craft version: Craft Pro 4.4.15 - PHP version: 8.1.16 - Image driver & version: Imagick 3.7.0 (ImageMagick 6.9.11-60) - Image driver and supported formats: jpg, jpeg, gif, png, webp, avif, heic - Custom encoders: webp, avif
jessedobbelaere commented 1 year ago

Closing this, found this option in the docs 😅 Had to add webp to my config as safe file format.

- 'safeFileFormats' => ['jpg', 'jpeg', 'gif', 'png'],
+ 'safeFileFormats' => ['jpg', 'jpeg', 'gif', 'png', 'webp'],