Problem/Motivation

When a retina derivative is generated outside RetinaImageStyleDownloadController (e.g., programmatic ImageStyle::createDerivative()) two errors are thrown:

Warning: Undefined array key "multiplier" in auto_retina_auto_retina_effect_alter() (auto_retina.module:104)

DivisionByZeroError in Drupal\auto_retina\Service\AutoRetina->optimizeImageSize() (AutoRetina.php:249)

The point is that auto_retina_auto_retina_create_derivative_alter() reads $style->getThirdPartySettings('auto_retina') and forwards it to the effect alter. Those settings are populated only by AutoRetina::prepareStyle(), which runs only on the retina download route. On every other code path the array is empty, so multiplier is missing and is passed as null into optimizeImageSize(), which then divides by zero.

Steps to reproduce

  1. Configure auto_retina with the default @2x suffix.
  2. Create an image style with a width/height effect.
  3. Call $style->createDerivative() directly with a @2x destination.

Proposed resolution

When the third-party settings are missing multiplier, call AutoRetina::prepareStyle($style, $destination) to derive them from the destination path before invoking the effect alter. Patch attached.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alex.bukach created an issue. See original summary.

alex.bukach’s picture

Assigned: alex.bukach » Unassigned
Status: Active » Needs review
chrisolof’s picture

Status: Needs review » Reviewed & tested by the community

Looks good - thanks Alex!

chrisolof’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.