Page List Custom Image Attribute
Permalink
Hi,
I have a custom Page List block that pulls image attributes and gives them different sizes depending on other attributes, and that part is working fine. Now, I need to use the original image (without getThumbnail) if the image is a gif.
I'm not getting there, I tried combining the two methods given in the original view.php for the page_list block but that gives me errors when I use
This is the code I have right now (without the gif thing)
here's the output:
How can I add in there that if it's gif, use the original image without resizing?
Thanks
I have a custom Page List block that pulls image attributes and gives them different sizes depending on other attributes, and that part is working fine. Now, I need to use the original image (without getThumbnail) if the image is a gif.
I'm not getting there, I tried combining the two methods given in the original view.php for the page_list block but that gives me errors when I use
$img_src = $img->getRelativePath();
This is the code I have right now (without the gif thing)
$largura = $page->getCollectionAttributeValue('largura'); $img = $page->getAttribute('thumbnail'); switch ($largura) { case "duas": $thumb = $ih->getThumbnail($img, 500, 9999, false); break; case "tres": $thumb = $ih->getThumbnail($img, 700, 9999, false); break; case "quatro": $thumb = $ih->getThumbnail($img, 900, 9999, false); break; default: $thumb = $ih->getThumbnail($img, 300, 9999, false); break;
Viewing 15 lines of 16 lines. View entire code block.
here's the output:
if($page->getAttribute('thumbnail')) { echo '<div class="image-container"><a href="' . $url . '" target="' . $target . '"><img class="thumbnail" src="' . $thumb->src . '" width="' . $thumb->width . '" height="' . $thumb->height . '" alt="" /></a></div>'; } else { echo '<div class="image-container"><a href="' . $url . '" target="' . $target . '"><img class="thumbnail" src="' . $this->getThemePath() . '/images/default_thumb.jpg" width="' . $thumb->width . '" height="' . $thumb->height . '" alt="" /></a></div>'; }
How can I add in there that if it's gif, use the original image without resizing?
Thanks
If I were to add another value in Attribute largura to say gif, how would the line have to be in the switch so that it would fetch the image without resizing it?
Once you have an image as a 'file object', you can call a method to get its extension and check for gif. Look up 'Files' in the developer documentation.
Hi JohntheFish,
I had seen that already, but I'm having difficulties getting the "thumbnail" attribute to be an object. I'm no developer, I'm a designer than can hack myself out of things, but I'm a little stuck on this one..
It keeps giving me these errors and I don't know how to get past them:
"Call to a member function on a non-object"
When I got these before, it was a matter of changing stuff like $c to $cobj, but I don't know what to do here..
could you give me a little more insight please?
Thanks for the help!
I had seen that already, but I'm having difficulties getting the "thumbnail" attribute to be an object. I'm no developer, I'm a designer than can hack myself out of things, but I'm a little stuck on this one..
It keeps giving me these errors and I don't know how to get past them:
"Call to a member function on a non-object"
When I got these before, it was a matter of changing stuff like $c to $cobj, but I don't know what to do here..
could you give me a little more insight please?
Thanks for the help!
When you do:
$img is either a file object, or a file ID. If its an ID you can use it to load the respective object.
Once you have a file object, you need to get a file version object, then from that get the extension.
Prtetty much all you need is on this page:
http://www.concrete5.org/documentation/developers/files/files-and-f...
As an alternative approach, if you don't like php code, this sort of thing is straightforward with Magic Data.
$img = $page->getAttribute('thumbnail');
$img is either a file object, or a file ID. If its an ID you can use it to load the respective object.
Once you have a file object, you need to get a file version object, then from that get the extension.
Prtetty much all you need is on this page:
http://www.concrete5.org/documentation/developers/files/files-and-f...
As an alternative approach, if you don't like php code, this sort of thing is straightforward with Magic Data.
Ok, got it working like so:
and then output it like this:
Cheers for the help.
$img = $page->getAttribute('thumbnail'); if (is_object($img)){ $ext = $img->getExtension(); $img_src = $img->getVersion()->getRelativePath(); }
and then output it like this:
if($page->getAttribute('thumbnail')) { if ($ext === gif){ //do something } else { //do something else } }
Cheers for the help.