single_page & thumbnail

Permalink 1 user found helpful
I have a package with several single_page pages.

Within one of the pages I wish to display the thumbnail of an asset from the library.

I have the fID of the asset... how do I (or indeed can I) use that to retrieve the thumbnail..?

JimboJetset
 
Remo replied on at Permalink Reply
Remo
$imgHelper = Loader::helper('image'); 
$imgHelper->getThumbnail($fileObj, 75, 75)->src
JimboJetset replied on at Permalink Reply
JimboJetset
Thats great remo... and it does work... however... this only works for images and I need to display a thumbnail regardless of file type just like in the asset manager where zip files show a zip icon thumbnail.

I could do it by parsing the file extension and having icons to hand as part of my package but it seems C5 is able to do this itself.

I guess what I'm really after is the thumbnail associated with the asset identified by fID

Do you know of a way to do this from a single page given the fID...?
Remo replied on at Permalink Best Answer Reply
Remo
ah I see. That should be possible too. You have to work on the FileVersion object though.

There's a method called getThumbnail. I've seen the first paramter set to 1 and 2. You can also check if there's a generate thumbnail by using hasThumbnail

Try to start by calling "getVersion" on your file object.. There you should find everything you need
Mnkras replied on at Permalink Reply
Mnkras
maybe something from here?

http://svn.concrete5.org/svn/concrete5/trunk/web/concrete/helpers/i...

public function getThumbnail($obj, $maxWidth, $maxHeight) {
      if ($obj instanceof File) {
         $path = $obj->getPath();
      } else {
         $path = $obj;
      }      
      $fh = Loader::helper('file');
      if (file_exists($path)) {
         $filename = md5($path . ':' . $maxWidth . ':' . $maxHeight . ':' . filemtime($path)) . '.' . $fh->getExtension($path);
      } else {
         $filename = md5($path . ':' . $maxWidth . ':' . $maxHeight . ':') . $fh->getExtension($path);
      }
      if (!file_exists(DIR_FILES_CACHE . '/' . $filename)) {
         // create image there
         $this->create($path, DIR_FILES_CACHE . '/' . $filename, $maxWidth, $maxHeight);
JimboJetset replied on at Permalink Reply
JimboJetset
Cheers Remo...

This was my solution...

$f = File::getByID(fID);
$fv = $f->getApprovedVersion();
$src = $fv->getThumbnail(1);