Split ImageStyle into the config entity and a separate event-based image processing service

Created on 18 July 2018, over 6 years ago
Updated 19 August 2024, 4 months ago

Problem/Motivation

The ImageStyle class is a config entity that besides doing the config entity, also has methods that do process images into derivatives.

This is probably the result of the migration of the image system from D7.

As things stand, though, this is causing issues -

  • the entity code is for instance invoking hooks
  • it's difficult for custom/contrib to override parts of the image derivatives generation process, for instance to change the derivative URL/URI, or to pre/postprocess image derivatives

Several issues were filed in that respect, to list some:
#2359443: Allow creating image derivatives from an Image object
Flexible scheme and URI for image derivatives Needs work
Make possible to respond to image derivative creation Needs work
ImageEffects of the same image style should be able to pass variables between them Needs work
Refactor ImageStyleDownloadController so derivatives can be generated by contrib modules Needs work
Allow image style derivatives of private images to be stored on the public file system Closed: duplicate
#2098247: Provide a hook for ImageStyle::createDerivative
#3218514: [PP-1] Deprecate passing path (instead of true URI) to ImageStyleInterface::buildUri($uri)

Proposed resolution

In #2359443-26: Allow creating image derivatives from an Image object , before stalling, we started discussing decoupling the config entity from the image derivative processing code.

This is implementing that:

  • separate the image derivative processing methods from the ImageStyle into a plugin, that takes ImageStyle as the config entity as in input, like the source URI or the Image object directly
  • deprecate the methods on the ImageStyle, leaving the code that calls the plugin methods instead
  • the plugin implements a fluent API to pass the variables needed and then executes the process required, bieng determining the derivative URI, or creating the derivative image, or getting the safety token
  • keeping full BC

Why a plugin?
So that the default implementation can be overridden e.g. to change the derivative URI calculation logic or to post-process an image derivative - only re-implementing the plugin methods that are necessary without touching the config entity code. But also, plugin allows to have parallel 'derivative processing engines' if someone wants that. For instance, Textimage contrib module has its own formatter and API that could leverage this plugin concept.

Remaining tasks

Review

User interface changes

None

API changes

Several methods deprecatedin ImageStyle, new plugin manager and a default plugin implemented.

Data model changes

None

Feature request
Status

Needs work

Version

11.0 🔥

Component
Image module 

Last updated 2 days ago

Created by

🇮🇹Italy mondrake 🇮🇹

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

  • Needs architectural review

    The issue is available for high level reviews only. If there is a patch or MR it is not to be set to 'Needs work' for coding standards, minor or nit-pick changes.

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.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇮🇹Italy mondrake 🇮🇹

    Rebased.

  • 🇺🇸United States bradjones1 Digital Nomad Life

    cspell error

    /var/www/html/core/modules/user/tests/src/Functional/UserPictureTest.php:123:34 - Unknown word (getfile)

  • Open on Drupal.org →
    Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    Not currently mergeable.
  • last update over 1 year ago
    Custom Commands Failed
  • last update over 1 year ago
    29,303 pass, 17 fail
  • last update over 1 year ago
    Custom Commands Failed
  • last update over 1 year ago
    29,414 pass, 4 fail
  • last update over 1 year ago
    29,421 pass, 2 fail
  • last update over 1 year ago
    Custom Commands Failed
  • last update over 1 year ago
    29,422 pass
  • Status changed to Needs review over 1 year ago
  • 🇮🇹Italy mondrake 🇮🇹

    rebased onto 11.x

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    Seems like something that could use a change record.

    For any contrib modules that add an image style will they have to do anything or will this work automatically.

  • Status changed to Needs review over 1 year ago
  • 🇮🇹Italy mondrake 🇮🇹

    @smustgrave re #81:

    Seems like something that could use a change record.

    For sure. However, 5 years after this was started, there seems to be little or no interest to move this forward - at least I cannot see reviews in this sense. So, either we simply just won't fix this, or a review in the sense of agreeing on the architecture (or a propositive disagreement) is needed. Writing a CR now would be simply too early/useless. Please leave to NR while we get a review - or close this.

    For any contrib modules that add an image style will they have to do anything or will this work automatically.

    Not sure I understand. You can add image effect plugins. Or configuration of image styles. Both are not affected by this.

  • 🇫🇷France andypost

    Did a first pass of review and wondered do we really need so many events fired while generation happening.

    Very probably it affects performance as each event is dispatched (as I got).

    Maybe instead it could use less events as some events can carry state of process

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    For #83

  • Status changed to Closed: won't fix over 1 year ago
  • 🇮🇹Italy mondrake 🇮🇹

    I give up, sorry.

    I could think of doing something in contrib, but core should at a minimum split the entity from the image processing code - in a way that it could be overridable. AFAICU it's not possible at the moment.

  • 🇺🇸United States smustgrave

    Wasn't trying to shoot down the idea. Not something I can speak heavily on though.

  • 🇮🇹Italy mondrake 🇮🇹

    No hard feelings, @smustgrave. Just I think after 5 years being open, there's no community interest at carrying this on. So I won't spend time on rerolls.

  • Status changed to Needs review over 1 year ago
  • 🇺🇸United States cmlara

    I really don't think this should be closed.

    I have been a bit booked by other tasks so I haven't been able to give it a test run, which I really wanted to do before commenting to hopefully better comment, but given there is a move to close it I feel a need to comment without having done the testing yet.

    @andypost in #83 you assert there is a 'probable' performance impact but did not provide a profile report with your post? Can you please attach the generated performance report file for the rest of us to review?

    While I've not traced every single event yet in this MR, the majority of the ones I have are only needed when an image derivative doesn't exist, the majority of times images are served from the file on disk. The most common to trigger event I would expect to be the buildUrl() events which need to be fired to generate links to ImageStyles Derivatives, though the flexibility of an event is necessary to allow all the changes that have been requested over the years.

    Could some events be combined? Without looking at every line, Maybe? But would it make sense? Most of these events are in response to a specific method being called, if no-one ever calls that method, why invoke the expense of gathering data that no-one will use?

    IMHO it would be a shame for this work to be lost especially since #83 didn't provide any objective data to justify moving to needs-work.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Closed the outdated MR

    Looking at the patch next

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Left some comments on the MR

    Keeping at NR and retaining the 'Needs architectural review' tag

  • 🇮🇹Italy mondrake 🇮🇹

    Thanks @larowlan for the review - I'll address your points but it may take a while.

  • 🇮🇹Italy mondrake 🇮🇹

    Replied to @larowlan's comments, inline.

  • Status changed to Needs work over 1 year ago
  • The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇺🇦Ukraine vlad.dancer Kyiv

    @mondrake, deviantintegral, @bradjones1 thanks a lot for your work!

    Just I think after 5 years being open, there's no community interest at carrying this on. So I won't spend time on rerolls.

    I'm working on a way of bringing UI to specify image styles beeing used for remote images for IntelligenceBank DAM and I think this issue is a good base for it. Typically DAMs like IB or PicturePark provides a way to generate image derivatives on their side, but there is a lack for selecting right image style in content context (like ckeditor, specific node, block). In Drupal we have many ways to map content item with right display settings, but it fails if image is remote and we don't need generate derivative ourselfs.

    I will check this issue more deeply!

Production build 0.71.5 2024