Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Dec 27, 2011 @ 11:33
    Bjarne Fyrstenborg
    0

    Change value of variable when value is greater than...

    Hi..

    I use these variables to set the height and width attributes of the image:

    <xsl:variable name="imgWidth" select="'170'"/>
    <xsl:variable name="scale" select="number(./productImage/DAMP/mediaItem[1]/Image/umbracoWidth) div $imgWidth"/>
    <xsl:variable name="imgHeight" select="round(number(./productImage/DAMP/mediaItem[1]/Image/umbracoHeight) div $scale)"/>

    <img src="{concat('/ImageGen.ashx?Image=',./productImage/DAMP/mediaItem[1]/Image/umbracoFile,'&amp;Width=',$imgWidth)}" class="productImage" alt="{$productName}" title="{$productName}" width="{$imgWidth}" height="{$imgHeight}" />    

    which also work fine.. but I would like to change the value of imgHeight when its value is greater than 170, then it should set the value a height to 170.. and the calculate the imgWidth from a height of 170.

    Something like:

    <xsl:variable name="imgHeight" select="'170'"/>
    <xsl:variable name="scale" select="number(./productImage/DAMP/mediaItem[1]/Image/umbracoHeight) div $imgHeight"/>
    <xsl:variable name="imgWidth" select="round(number(./productImage/DAMP/mediaItem[1]/Image/umbracoWidth) div $scale)"/>

    But I'm not sure how to use it with the first examle.. so it just use the values from the first snippet when imgHeight is lower than or equal 170 otherwise it sets imgHeight to 170 and then calculate a different imgWidth that always will be lower than 170. 

    Bjarne

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 27, 2011 @ 12:57
    Dirk De Grave
    0

    Hi Bjarne,

    you don't need to calculate the width of the image if height is to be set to 170, Check the documentation, all you need to do is calculate the height (170 or less) and do not specify width as a param, image will be resized to fit the specified height.

     

    Cheers,

    /Dirk

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Dec 27, 2011 @ 13:49
    Bjarne Fyrstenborg
    0

    Hi Dirk

    I use the variables to specify height and width attributes, so the browser knows the proportions before the image is loaded, which I also have done in the product list here: http://sub.ak-security.dk/da/shop/brandmateriel.aspx

    But on the page the image of the fire blanket has a small width and so the height will not fit in when I use 170px as width of the image.
    So in case that the height is greater than 170px I want to decrease the width to what fits proportional to the height. Then the image would have the proportions of 78 x 170 px (width / height).

    So that it's in these cases, where height is greater than width, I want to set the height to 170px and the width will be variable.

    Bjarne

Please Sign in or register to post replies

Write your reply to:

Draft