Cropping thumbnail in pagelist

Permalink
Goal: a PageList with cropped thumbnails - original pics have different shapes -> cropped squares.
Plan is to use a custom template. View.php and view.css copied from core are in application/blocks/page_list/templates/_nameofthecustomtemplate. Theme works otherwise (styles such as red border show) but I can't make cropping work. I know I should learn to code, but could someone help me meanwhile?


I have tried to implement the following instruction in the view.php:

* HOW TO USE IMAGE ATTRIBUTES:
       * 1) Uncomment the "$ih = Loader::helper('image');" line up top.
       * 2) Put in some code here like the following 2 lines:
       *      $img = $page->getAttribute('example_image_attribute_handle');
       *      $thumb = $ih->getThumbnail($img, 64, 9999, false);
       *    (Replace "64" with max width, "9999" with max height. The "9999" effectively means "no maximum size" for that particular dimension.)
       *    (Change the last argument from false to true if you want thumbnails cropped.)
       * 3) Output the image tag below like this:
       *      <img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />



I just can't figure out the right place. The following version (I've tried in several ways) does not break my site, but it does not work either....

(below is the first part of code - mangled version, my changes commented )

<?php
defined('C5_EXECUTE') or die("Access Denied.");
$th = Loader::helper('text');
$c = Page::getCurrentPage();
$dh = Core::make('helper/date'); /* @var $dh \Concrete\Core\Localization\Service\Date */
$ih = Loader::helper('image'); /********** This comes here ????  *********/
?>
<?php if ( $c->isEditMode() && $controller->isBlockEmpty()) { ?>
    <div class="ccm-edit-mode-disabled-item"><?php echo t('Empty Page List Block.')?></div>
<?php } else { ?>
<div class="ccm-block-page-list-wrapper">
    <?php if ($pageListTitle): ?>
        <div class="ccm-block-page-list-header">
            <h5><?php echo h($pageListTitle)?></h5>
        </div>

PaiviK
 
hutman replied on at Permalink Reply
hutman
You should be able to replace this:

$thumbnail = $ih->getThumbnail($img, 100, 100, true);    /**********   ????  *********/
        $thumbnail = false;    
        if ($displayThumbnail) {
               $thumbnail = $page->getAttribute('thumbnail');
        }


With this:

if ($img) {
               $thumbnail = $ih->getThumbnail($img, 100, 100, true);
               echo '<img src="'.$thumb->src.'" width="'.$thumb->width.'" height="'.echo $thumb->height.'" alt="" />';
        }


This is all assuming that the attribute handle of the image attribute you are trying to use is indeed "thumbnail"
PaiviK replied on at Permalink Reply
PaiviK
Thank you - but no success - syntax error, unexpected 'echo' (T_ECHO)
lowtech replied on at Permalink Reply
lowtech
Hi

Quote
syntax error, unexpected 'echo' (T_ECHO)


I think an extra echo was left in the code by mistake.

try

if ($img) {
               $thumbnail = $ih->getThumbnail($img, 100, 100, true);
               echo '<img src="'.$thumb->src.'" width="'.$thumb->width.'" height="'.$thumb->height.'" alt="" />';
        }



LT
PaiviK replied on at Permalink Reply
PaiviK
Nope, just got:
"Argument 1 passed to Concrete\Core\Html\Image::__construct() must be an instance of Concrete\Core\File\File, instance of stdClass given"

This morning I realized I was trying to be too clever - this can be done with styles - and with css I'm more familiar!

Thanks anyway!