Skip to content

Commit 7001386

Browse files
Merge pull request #1026 from cloudinary/fix/division-by-zero-error
Fix DivisionByZeroError in Responsive_Breakpoints
2 parents d679110 + 332a585 commit 7001386

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

php/delivery/class-responsive-breakpoints.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,22 @@ public function add_features( $tag_element ) {
127127
* @return array
128128
*/
129129
protected function apply_breakpoints( $tag_element ) {
130+
if ( empty( $tag_element['id'] ) ) {
131+
return $tag_element;
132+
}
133+
134+
$settings = $this->settings->get_value( 'media_display' );
135+
$max = $settings['max_width'];
136+
$min = $settings['min_width'];
137+
$width = (int) $tag_element['width'];
138+
$height = (int) $tag_element['height'];
139+
$debug_key = 'responsive_breakpoints_' . $tag_element['id'];
140+
141+
if ( ! $width || ! $height ) {
142+
Utils::log( 'Missing width or height for image with ID: ' . $tag_element['id'], $debug_key );
143+
return $tag_element;
144+
}
130145

131-
$settings = $this->settings->get_value( 'media_display' );
132-
$max = $settings['max_width'];
133-
$min = $settings['min_width'];
134-
$width = $tag_element['width'];
135-
$height = $tag_element['height'];
136146
$size_tag = '-' . $width . 'x' . $height . '.';
137147
$step = $settings['pixel_step'];
138148
$ratio = $width / $height;

0 commit comments

Comments
 (0)