Trying to modify a block

Permalink
Hi,
Im trying to modify a designer content pro block to render a thumbnail at a set size, rather than the full image.

Here's what I have:
<?php foreach ($controller->getRepeatingItems() as $item): 
            $ih = Loader::Helper('image');
            $img = $item->image;
            $thumb = $ih->getThumbnail($img, 590, 486);
            if(isset($thumb)) {
            ?>
            <li><img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="Wedding Photo" /></li>
            <?php } ?>
            <?php endforeach; ?>


The problem is I get the following errors:
Warning: file_exists() expects parameter 1 to be a valid path, object given in /home/devruss/public_html/updates/concrete5.6.3.3/concrete/core/helpers/image.php on line 302
Warning: file_exists() expects parameter 1 to be a valid path, object given in /home/devruss/public_html/updates/concrete5.6.3.3/concrete/core/helpers/image.php on line 304
Catchable fatal error: Object of class DcpFieldDisplay_Image could not be converted to string in /home/devruss/public_html/updates/concrete5.6.3.3/concrete/core/helpers/image.php on line 310


Please can you tell me how can I fix it?
Thanks
Dave

madesimplemedia
 
mnakalay replied on at Permalink Best Answer Reply
mnakalay
Hey Dave,

The problem here is that the $item returned is not really an image object as C5 understands it.

To do what you want there are 2 ways.

First one
<?php foreach ($controller->getRepeatingItems() as $item): ?>
   <?php
   $item->image->display(590, 486);
   ?>
<?php endforeach; ?>

Note that the display() function takes 3 argument. It's display(width, height, crop) and crop is a boolean set as false by default.

Now, in your code I see you have some custom title tags so if you want to control the markup do:
<?php foreach ($controller->getRepeatingItems() as $item): ?>
<?php 
   $thumb = $item->image->getImageObj(590, 486);
   if(isset($thumb)) { ?>
      <li><img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="Wedding Photo" /></li>
   <?php } ?>
<?php endforeach; ?>

The getImageObj() function works the same way the display one works getImageObj(width, height, crop)
madesimplemedia replied on at Permalink Reply
madesimplemedia
Thanks Nour, perfect! :)