Can't figure out how to display thumbnails
Permalink
Hello,
I'm at my wit's end in attempting to display a list of image thumbnails. I've spent hours reading posts and trying out bits and pieces of tutorials, but with no luck. I'm afraid I am simply missing some key concept (yeah, new to C5), so I hope someone can beat some sense into my brain.
Briefly, I've converted a set of static pages into a new C5 theme, with most things working well so far. One of my theme templates is based upon a custom image gallery I had previously used for a client, and he would like to continue using this gallery, so this is what I'm trying to get thumbnails into.
So I've created a "photo" page based upon my theme's gallery template, and with file manager have uploaded several images and have placed them into a file set. I can loop through the file set and get the paths to the images and display them in normal size. However I CANNOT figure out how to get the thumbnails in order to place them into an unordered list. As I have little experience with php, I have found snippets of code, and have the following php to get the normal image paths, but what am I doing wrong for the thumbnails? Do I need to create some type of attributes in file manager?
<?php
$ih = Loader::helper('image');
Loader::model('file_set');
Loader::model('file_list');
$page = Page::getCurrentPage();
$fs = FileSet::getByName('Gallery Images');
$fileList = new FileList();
$fileList->filterBySet($fs);
$fileList->filterByType(FileType::T_IMAGE);
$files = $fileList->get();
foreach($files as $image){
$source = $image->getRelativePath(); ///// Note - this works fine to get the normal images /////
// Now here is where I try to get the thumbnails:
$img = $page->getAttribute($source); // Grab the image
if(isset($img)) { // Make sure we have an image
$thumbnail = $ih->getThumbnail($img, 50, 50, true); // Create the thumbnail
}
echo '<li><a href="'.$source.'" class="gallery_img" title=""><img src="' . $thumbnail . '" width="50" height="50" alt="" title="View larger image"></a></li>';
}
echo '</ul>';
?>
Looks like this turned into a longer post than I had intended. Sorry.
I would be most grateful for some guidence here. Thank you.
I'm at my wit's end in attempting to display a list of image thumbnails. I've spent hours reading posts and trying out bits and pieces of tutorials, but with no luck. I'm afraid I am simply missing some key concept (yeah, new to C5), so I hope someone can beat some sense into my brain.
Briefly, I've converted a set of static pages into a new C5 theme, with most things working well so far. One of my theme templates is based upon a custom image gallery I had previously used for a client, and he would like to continue using this gallery, so this is what I'm trying to get thumbnails into.
So I've created a "photo" page based upon my theme's gallery template, and with file manager have uploaded several images and have placed them into a file set. I can loop through the file set and get the paths to the images and display them in normal size. However I CANNOT figure out how to get the thumbnails in order to place them into an unordered list. As I have little experience with php, I have found snippets of code, and have the following php to get the normal image paths, but what am I doing wrong for the thumbnails? Do I need to create some type of attributes in file manager?
<?php
$ih = Loader::helper('image');
Loader::model('file_set');
Loader::model('file_list');
$page = Page::getCurrentPage();
$fs = FileSet::getByName('Gallery Images');
$fileList = new FileList();
$fileList->filterBySet($fs);
$fileList->filterByType(FileType::T_IMAGE);
$files = $fileList->get();
foreach($files as $image){
$source = $image->getRelativePath(); ///// Note - this works fine to get the normal images /////
// Now here is where I try to get the thumbnails:
$img = $page->getAttribute($source); // Grab the image
if(isset($img)) { // Make sure we have an image
$thumbnail = $ih->getThumbnail($img, 50, 50, true); // Create the thumbnail
}
echo '<li><a href="'.$source.'" class="gallery_img" title=""><img src="' . $thumbnail . '" width="50" height="50" alt="" title="View larger image"></a></li>';
}
echo '</ul>';
?>
Looks like this turned into a longer post than I had intended. Sorry.
I would be most grateful for some guidence here. Thank you.
OMG! bbeng89, you rock! That works perfectly. The key was "$thumbnail->src". I definitely was not aware of how to apply $thumbnail properly.
Thanks so much.
Thanks so much.
No problem, glad I could help!
even simpler:
while $f is your file object and $level is the thumbnail level
cheers
while $f is your file object and $level is the thumbnail level
$f->getThumbnailSRC($level);
cheers
If you have the list of file objects you should be able to just generate a thumbnail using the $image object. So you could try changing your code to something like this: