How to get a thumb image from a previous page when the thumb was not created yet?

Hey, how to get a thumb image from a next or previous page when the thumb was not created yet?

  <?php if($page->hasPrevVisible() && !empty($page->prevVisible()->image_teaser())): ?>
  <a href="<?php echo $page->prevVisible()->url() ?>">
    <?php echo thumb($page->prevVisible()->image($page->prevVisible()->image_teaser()), array('width' => 240, 'height' => 135, 'crop' => true)); ?>
  </a>
  <?php endif ?>

I get the following error:
// check for a valid image
if(!$this->source->exists() || $this->source->type() != ‘image’) {
throw new Error(‘The given image is invalid’, static::ERROR_INVALID_IMAGE);
}

thanks!

Does the image exist? It is recommended to always check if the image exists (it may be that you selected an image, but the image was later removed, so only checking if the field contains a value is not sufficient).

<?php if($page->hasPrevVisible() && !empty($page->prevVisible()->image_teaser())): ?>

<?php 
  $image = $page->prevVisible()->image_teaser()->toFile();
  if($image) {
    echo thumb($image, array('width' => 240, 'height' => 135, 'crop' => true));
  } 
?>

<?php endif ?>

nice - this solved the problem!

thanks!