"Division by zero" error with custom image template in: 5.6.3.1

Permalink
Hi There,

I made this template a couple of years ago but it seems to be triggering a "Division by zero" error - can anyone see what might be causing this?

Here's my template:
<?php
  defined('C5_EXECUTE') or die(_("Access Denied."));
  $ih = Loader::helper('image'); // load the c5 image helper
  $img = File::getByID($fID); // get the image
  $imgPath = $img->getURL(); // get the image path
  $imgTitle = $img->getTitle(); // get the image title
  $imgThumb = $ih->getThumbnail($img, $maxWidth, $maxHeight); // render thumb using the size entered in the block edit screen
  $linkURL = $controller->getLinkURL(); // get the link url
  $linkTitle = $controller->getaltText(); // get the link text
?>
<p>
  <a class="pop-image" href="<?= $imgPath ?>" title="<?= $imgTitle ?>">
    <img src="<?= $imgPath ?>" alt="<?= $imgTitle ?>" />
  </a>
</p>


Any pointers in the right direction would be much appreciated.

Cheers

Ben

 
cmscss replied on at Permalink Reply
Must of been something dumb in my php - changed it to this and everything works:

<?php
  defined('C5_EXECUTE') or die(_("Access Denied."));
  $ih = Loader::helper('image'); // load the c5 image helper
  $img = File::getByID($fID); // get the image
  // $img->getURL(); = get the image path
  // $img->getTitle(); = get the image title
  // $ih->getThumbnail($img, $maxWidth, $maxHeight); = render thumb using the size entered in the block edit screen
  // $controller->getLinkURL(); = get the link url
  // $controller->getaltText(); = get the link text
?>
<a class="pop-image" href="<?= $img->getURL(); ?>" title="<?= $img->getTitle(); ?>">
  <img src="<?= $img->getURL(); ?>" alt="<?= $img->getTitle(); ?>" />
</a>
Remo replied on at Permalink Best Answer Reply
Remo
you're using undefined variables. maxWidth and maxHeight aren't defined and can therefore cause a message like division by zero.. The second template is different, it shows the picture in its original size. That's fine if that's what you want, but the block allows you to specify a width and height which you ignore in that template..
cmscss replied on at Permalink Reply
Thanks heaps for your reply Remo,

Is that because there's nothing entered in the block edit window or because maxWidth/maxHeight aren't actually variables that are part of the block?

Cheers

Ben
Remo replied on at Permalink Reply
Remo
Not quite sure without checking, but you can easily figure this out on your own. Just enter a value for both width and height and add an "echo $maxWidth" in your view.php. If there's a value, you just have to add a check and a default value..