Using the height and width of the images and thumbnails in your Gallery templates should be pretty straightforward, not? Well I guess it wasn't... Until now!
The method described here originates from the IDT blog and was written in 2011 by Manuel. The tutorial there doesn't work anymore with the latest CMS Made Simple™ releases due to the Smarty security settings.
We use the getimagesize PHP function for this!
But in the latest Smarty releases due to security settings PHP functions aren't available by default...
If you do want to use PHP functions, you have to enable them by adding this line to your CMSMS config.php file:
This config variable loosens some of the security configuration for smarty templates. Particularly enabling this option allows the use of any PHP function as a Smarty plugin. You better not use this option if you are allowing content to be submitted for display on your website from untrusted sources! If the function works without this line, you better not add it!
We now can use the getimagesize function with the foreach loop!
As this outputs an array, we need to use the print_r modifier to see the output the PHP function generates.
Using the print_r modifier, we get to see the Array content:
Seeing the output using print_r is all fine and dandy but we can't use the values yet in our template just yet!
We need to store the values generated by the getimagesize modifier in an array so we can use them later on.
To achieve this, we assign the output of the getimagesize to a variable (actually it's an array but PHP takes care of this for you automatically)
Note: You can change $image->file to $image->thumb if you are after the thumbnail sizes.
All the values are now stored in the $imagesize array.
To use the values in our template we can now simply call $imagesize[##THE VALUE YOU WANT TO USE##]
Now we can add $imagesize[#] in the Gallery template like:
The HTML output should be:
We take this image:
The output is:
Array (  => 400  => 320  => 2  => width="400" height="320" [bits] => 8 [channels] => 3 [mime] => image/jpeg ) 1
No comments yet...