Getting the image dimensions in smarty
Posted: Mon Jul 25, 2011 9:32 pm
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!
Note: the codes below are supposed to be located inside the main "foreach" in your gallery template!
1. How can we get the image sizes using a php modifier?
We use the getimagesize modifier for this:
This returns an Array containing all necessary information:
ps: you can see the contents of the array generated by the "getimagesize modifier" by using:
2. Getting the values out of the array and storing them in variables.
Below you will find the "cut and paste" code that will provide you with separate variables for the height and width of your full size images in the gallery module.
(change the "i" variable, the "getimagesizeval" and change "$image->file" to "$image->thumb" for the thumbnail sizes)
If you have correctly placed the code above inside of the main foreach loop in your gallery template, this will result in the following variables being available to use in your templates:
If you have something to share, please don't hold back!
You can also find this article on the i-do-this blog:
http://www.i-do-this.com/blog/49/Gettin ... -in-smarty
Greetings,
Manuel
Note: the codes below are supposed to be located inside the main "foreach" in your gallery template!
Code: Select all
{foreach from=$images item=image}
We use the getimagesize modifier for this:
Code: Select all
{$image->file|getimagesize}
Code: Select all
Array ( [0] => 385 [1] => 100 [2] => 2 [3] => width="385" height="100" [bits] => 8 [channels] => 3 [mime] => image/jpeg ) 1
Code: Select all
{$image->file|getimagesize|@print_r}
Below you will find the "cut and paste" code that will provide you with separate variables for the height and width of your full size images in the gallery module.
(change the "i" variable, the "getimagesizeval" and change "$image->file" to "$image->thumb" for the thumbnail sizes)
Code: Select all
{assign var="i" value=0}
{foreach from=$image->file|getimagesize item="image"}
{assign var="i" value=$i+1}
{capture assign="getimagesizeval"}getimagesizeval{$i}{/capture}{capture assign="$getimagesizeval"}{$image}{/capture}
{/foreach}
Code: Select all
getimagesizeval1 = 385
getimagesizeval2 = 100
getimagesizeval3 = 2
getimagesizeval4 = width="385" height="100"
getimagesizeval5 = 8
getimagesizeval6 = 3
getimagesizeval7 = image/jpeg
You can also find this article on the i-do-this blog:
http://www.i-do-this.com/blog/49/Gettin ... -in-smarty
Greetings,
Manuel