Allow processors to generate multiple images

Created on 5 June 2019, almost 6 years ago
Updated 21 March 2024, 12 months ago

Problem/Motivation

Currently a processor is sent a single $temp_image_uri and returns success or failure. In some cases, it may be desired behavior for the processor to create a copy of the file. In example being cloning an uncompressed JPEG into WebP format, before additional compression occurs to the JPEG. You could then tie all the pieces together by having a pipeline that looks like:

- WebP (accepts other formats and generates WebP copy of image file)
- Krakin (for jpg and png)

The responsive image module can then be responsible for making WebP images available for browsers that support it.

Because this module takes over the ImageStyle class, I've been unable to really find another way to do this. Especially because we want WebP to be able to act before any other quality/compression takes place. There is work being done to make WebP be supported in core, however until it has full browser support(and OS for that matter), we'll probably be converting from other image formats for the foreseeable future.

Proposed resolution

The easiest way this could be done is just providing an event or hook within Drupal\imageapi_optimize\Entity\ImageAPIOptimizePipleline::applyToImage:

   if ($image_changed) {
        // Copy the temporary file back over the original image.
        file_unmanaged_move($temp_image_uri, $image_uri, FILE_EXISTS_REPLACE);
      }

And then just let the submodules take care of the extra behavior. However, we could go further and actually create multiple image handling, but that might open an entirely new can of worms.

Remaining tasks

Discuss options

User interface changes

TBD.

API changes

TBD.

Data model changes

TBD.

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States michaellander

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom Driskell

    The approach by @larowlan seems very useful to me, as it means existing modules are unaffected and new ones can receive additional information via the new interface. Over time perhaps some more helpers can be added for moving temporary files too but this would be a good start and works great for me.

  • πŸ‡ΊπŸ‡ΈUnited States michaellander

    I thought this was interesting: WebP fallback image β†’ .. Their argument is that we aren't gaining the full benefits of compression with modules like ImageAPI Optimize Webp β†’ because we aren't compressing from the source file. My original rationale was to avoid running images through image style processors multiple times(once as jpg, once as webp, for example), though that wouldn't matter so much if it's only running it through the image style as it's being requested for the first time. I think it's also more and more likely that people will favor AVIF with a WebP fallback, and almost never want to keep the original file format if JPG, PNG, etc..

    Perhaps finding a way where we would no longer need to do the derivative handling at the imageapi_optimize level, and let optimize just worry about optimization.

    I haven't looked at this stuff in awhile and will try and get caught back up.

  • Status changed to Needs work 21 days ago
  • πŸ‡ΊπŸ‡ΈUnited States greggles Denver, Colorado, USA

    8.x-2.x branch is no longer supported, so moving to needs work for a porting.

    Is this feature request still relevant for the 4.x branches? If so it seems the version should be updated. If not I guess this could be closed as outdated. Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States michaellander

    @greggles, we are working on a new approach to image type derivatives so that we can support more complex workflows, for example:

    Original image is .jpg

    • Generated AVIF
    • Generated WebP(fallback)
    • Original JPG (removed from display)

    Original image is .webp

    • Generated AVIF
    • Original WebP(fallback)

    Original image is .avif

    • Original AVIF
    • Generated WebP(fallback)

    This will also allow builders to mix in other standards, like if you have a photography site or maybe product shots and want to use Jpeg XL(with webp fallback) for those displays. We are nearing completion, and have a solution for this, although not the most elegant. Ultimately we will override the ImageStyle entity class and have versions that support core and imageapi_optimize when enabled. Because we are trying to support both core and imageapi_optimize versions, I'm not sure a solution here really save us too much effort. Ultimately a solution might be a better fit for core.

  • πŸ‡ΊπŸ‡ΈUnited States michaellander
Production build 0.71.5 2024