Jump to content

How to display cropImages


Alex
 Share

Recommended Posts

I have installed the thumbnail cropping tool, edited my existing "images" field so it uses the fieldtype "CropImage"

My crop setups are the default:

thumbnail,100,100

This is working fine i can create cropped thumbnails,

I just need some pointers on how use it on my template where I want to display the cropped thumbnail...

This is the template code:

<?php
/**
* Home template
*
*/
include("./head.inc");
echo $page->body;
echo "<ul id='portfolio_list'>";
$items = $pages->get('/portfolio/')->children("limit=6"); // Here we take children of portfolio page (limit=6)
foreach($items as $item) { //Loop through them
	    $image = $item->images->first();
  $thumb = $image->size(100,100);
	    echo "<li><a href='{$item->url}'><img src='{$thumb->url}' alt='{$thumb->description}'>";
	    echo "<br />{$item->title}<br />{$thumb->description}</a></li>";
}
echo "</ul>";
include("./foot.inc");

Thanks

Alex

Link to comment
Share on other sites

If you use Thumbnails module, then you don't do the resizing on the template file. So no size() method if you use thumbnails.

In your template code I would change this:

$image = $item->images->first();

To this:

$thumb = $item->images->first();

Then I would remove the next line (where you use size() method).

Rest of the code you can keep, but change {$thumb->url} with $thumb->getThumb('thumbnail'). I'm not sure, but you might need to write it like this:

echo "<img src='". $thumb->getThumb('thumbnail') ."' />
  • Like 1
Link to comment
Share on other sites

I just merged Pete's pull request, so if you grab latest version of Thumbnails then it should work. I haven't tested this yet myself, but I will soon too. Special thanks to Pete for working on this and adding great new feature (template specific crops).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...