From e1c53921d3ac4574486b420d6da9c2843f144d76 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 20 Mar 2009 20:33:20 +0000 Subject: Don't divide by zero in thumb_tag if there's no thumbnail --- core/models/item.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'core/models') diff --git a/core/models/item.php b/core/models/item.php index 2bfecc76..4790e31a 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -328,14 +328,22 @@ class Item_Model extends ORM_MPTT { public function thumb_tag($extra_attrs, $max=null) { $width = $this->thumb_width; $height = $this->thumb_height; - if (isset($max)) { - if ($width > $height) { - $height = (int)($max * ($height / $width)); - $width = $max; - } else { - $width = (int)($max * ($width / $height)); - $height = $max; + + if ($height) { + if (isset($max)) { + if ($width > $height) { + $height = (int)($max * ($height / $width)); + $width = $max; + } else { + $width = (int)($max * ($width / $height)); + $height = $max; + } } + } else { + // Missing thumbnail, can happen on albums with no photos yet. + // @todo we should enforce a placeholder for those albums. + $width = 0; + $height = 0; } $attrs = array_merge($extra_attrs, array( -- cgit v1.2.3