working with concrete/blocks/library_file/controller.php

Permalink
Hi, trying to get a thumbnail to come back out of this inside the current image block, but I am stumped as to where to start. I have checked out the video block for a little guidance and peered into the library_file/controller to see what it is doing, but I just can't seem to get it to output the thumbnail. I am relatively new to php and I wanted to learn this on my own as a learning experience, but 6 hours today is about when I decide to throw in the towel and ask for a little guidance :)

Thank you in advance.


-Scott Conrad

ScottC
 
andrew replied on at Permalink Reply
andrew
You are definitely right that most of these operations will always take place in the LibraryFileBlockController object. This is the sort of generic file block object that other blocks like video, image, etc... will reference.

If you download the latest release, 5.1, we've actually simplified this stuff a bit, and made it much more powerful. You can create thumbnails programmatically on the fly of whatever dimensions you like (the aspect ratio of the source image will be preserved.) So, let's see you wanted to modify the image block template so that, instead of just showing the image, you showed a thumbnail image that was no larger than 300x300, and it linked to the original image.

This is the code that accomplishes just that:

<?php
$fo = $controller->getFileObject();
print '<a href="' . $fo->getFileRelativePath() . '">';
$fo->outputThumbnail(200, 200);
print '</a>';
?>


The first line gets the file object from the image block. This represents the image object that is saved with the image block when you save it (the first one you select.) The second line starts printing the link. The third line outputs a thumbnail no larger than 200x200 pixels. If the thumbnail does not exist at that size, a version of it will be created and saved in the cache directory. Finally the fourth line finishes the link.

Like I mentioned - this is only available in 5.1 - it was added at the last minute. But if you use the file objects whenever you're building your own blocks, you should have a lot of flexibility as to how you can display thumbnails.
ScottC replied on at Permalink Reply
ScottC
Andrew, thank you :)

I am sure this code will help a bunch of people. I was trying to do it inside the controller and just run it out with the getContentAndGenerate() function return value. At one point i was bringing down my apache server!