Search

Hello, If I generate an image using 0, the width of the thumbnail is calculated for me. Like:

/image/1/0/300/

But, how do I get the value of that width? so i can put it into the html”

<img src="" width="X" height="Y">

thanks!

You can’t I’m afraid. Why not leave the width attribute off completely?

Ay, the layout will be quite jQuery-heavy, and javascript needs the dimensions before the image(s) is/are loaded. Waiting for all images to load before layouting is not an option.

I’m familiar with PHP and getimagesize. I could do the calculations myself, I’m just not sure where and how to put the code…

thanks, J

When you get your image from a upload-field it provides the original width- and height. Using some math you can calculate the corresponding height:

XML:

<image size="22 KB" path="/uploads/portfolio/images" type="image/jpeg">
    <filename>my_image.jpg</filename>
    <meta creation="2010-09-28T12:26:18+02:00" width="626" height="202" />
</image>

XSLT:

<!-- To calculate the correct height: -->
<img src="/image/2/100/0/5{image/@path}/{image/filename}" width="100">
    <xsl:attribute name="height">
        <xsl:value-of select="round(image/meta/@height * (100 div image/meta/@width))" />
    </xsl:attribute>
</img>
<!-- To calculate the correct width: -->
<img src="/image/2/0/100/5{image/@path}/{image/filename}" height="100">
    <xsl:attribute name="width">
        <xsl:value-of select="round(image/meta/@width * (100 div image/meta/@height))" />
    </xsl:attribute>
</img>

Never underestimate the power of math! ;-)

Ha! One day, I shall be a xslt ninja as well

many thanks! J

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details