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
- Configure auto_retina with the default
@2xsuffix. - Create an image style with a
width/heighteffect. - Call
$style->createDerivative()directly with a@2xdestination.
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.
Issue fork auto_retina-3590441
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
Comment #3
alex.bukach commentedComment #4
chrisolofLooks good - thanks Alex!
Comment #5
chrisolof