Copied to clipboard

Flag this post as spam?

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


  • Harald Ulriksen 207 posts 249 karma points
    Oct 31, 2011 @ 10:07
    Harald Ulriksen
    0

    Scaling images

    What's the recommended method for scaling images for use in the generated pdf files? 

    As I see it we can either scale using imagegen, in the pdf or a combination of both. 

    I have a block 17cm x 5cm. I must be able to let the user pick 1, 2 or 3 images. If I have more than one image they should be equal in size, resize smallest dimension and cut the other one.

    The result should either be on image 17 x 5cm, two images 8.5cm x 5cm or 3 images at  5.6667cm x 5cm (with the last image beeing constrained by 17cm containing block). 

    Any suggestions? I've tried using image gen and calculating pixels based on dpi, but it does not mot match 100%

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Oct 31, 2011 @ 10:25
    Darren Ferguson
    0

    Hi Harald, 

    What are your source image types? JPEG? Are they all at the same DPI.

    In any pixel to CM conversion you aren't always going to get a whole number.

    I would have a three way case statement - one for each variation of 1, 2 or 3 images.

    if you had 3 images at 200 DPI your pixel width is 1339 this doesn't divide by 3 so you'd have to do the following:

    Image 1 - 447px wide

    Image 2 - 446px wide

    Image 3 - 446 px wide

    You'd also have to then do a crop to make sure that they all end up at the desired height.

    Does this make sense? I would use imagegen to do these sizing.

    Let me know if not.

     

     

     

  • Harald Ulriksen 207 posts 249 karma points
    Oct 31, 2011 @ 10:44
    Harald Ulriksen
    0

    More or less what I am doing now. 

    I have two block containers - the outer one with correct size and overflow hidden. The inner one a bit bigger. I then resize the images based on dpi, mm and inches conversion using image gen - they will fit more or less and what is outside my goal width will be cut by the outer small block container.

    Note that image gen allowupsize may cause confusion when some images does not consume all the expected space. 

     

  • Harald Ulriksen 207 posts 249 karma points
    Oct 31, 2011 @ 10:46
    Harald Ulriksen
    0
                <fo:block-container overflow="hidden" height="5cm" width="16cm">
    <fo:block-container width="17cm">
    <fo:block
    width="17cm"
    height="5cm"
    overflow="hidden">
    <xsl:call-template name="HeaderImages">
    <xsl:with-param name="images" select="selectedMedia/MultiNodePicker/nodeId" />
    </xsl:call-template>

    </fo:block>
    </fo:block-container>
    </fo:block-container>

     

       <xsl:if test="count($images) &gt; 0">

    <xsl:variable name="dpi">120</xsl:variable>
    <xsl:variable name="mmToInches" select="1 div 2.54" />

    <xsl:variable name="widthMm" select="round(168 div count($images))" />
    <xsl:variable name="widthPixels" select="round($widthMm * $dpi * $mmToInches div 10)" />
    <xsl:variable name="heightMm" select="50" />
    <xsl:variable name="heightPixels" select="round($heightMm * $dpi * $mmToInches div 10)"/>

    <xsl:for-each select="$images">
    <xsl:variable name="media" select="umbraco.library:GetMedia(., 0)" />


    <xsl:variable name="imageUrl" select="concat('http://',$siteRoot,'/imagegen.ashx?image=',$media/umbracoFile,'&amp;width=',$widthPixels,'&amp;height=',$heightPixels,'&amp;crop=resize')"/>

    <fo:external-graphic src="url({$imageUrl})"
    margin="0"
    padding="0" />
    </xsl:for-each>

    </xsl:if>



  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Oct 31, 2011 @ 10:47
    Darren Ferguson
    0

    So - what is the outcome the scaling just looks wrong - or the images don't match the dimensions you specify?

    Perhaps post an example - email it to me if it is confidential.

    D

  • Harald Ulriksen 207 posts 249 karma points
    Oct 31, 2011 @ 10:52
    Harald Ulriksen
    0

    Well, one part was the ImageGen allowupsize which were specifically set in the imagegen.config with overridequerystring=true. I also have issues changing the DPI so I'm currently stuck to 120, but that's not a problem as of now.

    Mainly I was looking for other aproaches, just in case someone had a better suggestion.

     

Please Sign in or register to post replies

Write your reply to:

Draft