Division by 0 in template_preprocess_image_style_preview

Created on 24 April 2020, almost 5 years ago
Updated 25 February 2025, about 1 month ago

Problem/Motivation

When Editing Image Styles and creating an aspect-preserving image resize, you would typically insert only one of width or height in the image resize.

The code in template_preprocess_image_style_preview (line ~68), however, assumes that both width and height have been specified, and tries to divide width by height to get a ratio.

If height has not been specified in the scale setup, a divide by 0 error is thrown.

64:    $variables['preview']['derivative']['height'] = round($variables['preview']['derivative']['width'] / $variables['derivative']['width'] * $variables['derivative']['height']);

68:    $variables['preview']['derivative']['width'] = round($variables['preview']['derivative']['height'] / $variables['derivative']['height'] * $variables['derivative']['width']);

Proposed resolution

Fix the code to understand that sizes may not be specified or even available.

Remaining tasks

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

image system

Created by

🇬🇧United Kingdom rivimey

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.

Production build 0.71.5 2024