Copied to clipboard

Flag this post as spam?

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


  • Damon Bauer 48 posts 95 karma points
    Nov 20, 2012 @ 21:47
    Damon Bauer
    0

    Help displaying image from Media Picker with ImageGen

    Hi there,

    I'm trying to display and image from the Media Picker and ImageGen, but I can't seem to get it working properly. Here's what I've got:

    <xsl:variable name="image" select="umbraco.library:GetMedia(./previewImage, 0)/umbracoFile" />

    <xsl:if test="$image">

    <img src="/ImageGen.ashx?image={$image}&amp;width=100&amp;height=100" />

    </xsl:if>

     

    I'm getting ever-so-helpful error:

    System.OverflowException: Value was either too large or too small for an Int32. 

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 20, 2012 @ 21:49
    Chriztian Steinmeier
    0

    Hi Damon,

    Depending on where in the XSLT file you're doing this, you may need to tuck $currentPage onto the property, e.g.:

    <xsl:variable name="image" select="umbraco.library:GetMedia($currentPage/previewImage, 0)/umbracoFile" />

     

    /Chriztian

  • Damon Bauer 48 posts 95 karma points
    Nov 20, 2012 @ 21:52
    Damon Bauer
    0

    Thanks for the suggestion. Unfortunately, I'm inside of an <xsl:for-each>, so I'm doing:

     <xsl:template match="/">
    
        <div class="grid">
            <xsl:for-each select="$currentPage/descendant::*[@isDoc]">            
    
                <div class="phone">
                    <div class="left">
                        <xsl:variable name="image" select="umbraco.library:GetMedia($currentPage/previewImage, 0)/umbracoFile" />                 
                        <xsl:if test="$image">
                            <img src="/ImageGen.ashx?image={$image}&amp;width=100&amp;height=100" />
                        </xsl:if>
                    </div>
                    <div class="right">
                        <h3>
                            <a href="{umbraco.library:NiceUrl(./@id)}"><xsl:value-of select="./@nodeName" /></a>
                        </h3>
                        <p><xsl:value-of select="./featuredOnHomePageText" disable-output-escaping="yes" /></p>
                    </div>
                </div>
            </xsl:for-each>
        </div>
    
    </xsl:template>

    Am I going about this incorrectly?

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 20, 2012 @ 22:03
    Chriztian Steinmeier
    0

    Yeah, ok - makes sense.

    Well in that case, some (or maybe just one) of your pages has no image picked - and since you're calling the GetMedia() function anyway, it errors out. Here's a way to cope with that:

    <!-- Make sure an image was picked -->
    <xsl:if test="normalize-space(previewImage)">
        <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($currentPage/previewImage, 0)" />                                       
        <!-- Just to be safe from picked image having been deleted afterwards...   -->
        <xsl:if test="not($mediaNode[error])">
            <img src="/ImageGen.ashx?image={$mediaNode/umbracoFile}&amp;width=100&amp;height=100" />
        </xsl:if>
    </xsl:if>
    
    (Goes inside the <div class="left">)

    /Chriztian

  • Damon Bauer 48 posts 95 karma points
    Nov 20, 2012 @ 22:16
    Damon Bauer
    0

    Chriztian -

    Thanks for the help. The logic behind no image & get media causing an error makes perfect sense.

    Unfortunately, I dropped in the code you gave above, and I'm still getting the  error: System.OverflowException: Value was either too large or too small for an Int32.

    If I remove all the image code that we're toying with, the error goes away. I also tried using ($currentPage/...) and (./...) to no avail.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 20, 2012 @ 22:20
    Chriztian Steinmeier
    0

    Yeah - that's because I'm a clown, posting wrong code :-)

    You of course need to remove the $currentPage/ prefix inside the call to GetMedia() ...

    <!-- Make sure an image was picked -->
    <xsl:if test="normalize-space(previewImage)">
        <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(previewImage, 0)" />                                       
        <!-- Just to be safe from picked image having been deleted afterwards...   -->
        <xsl:if test="not($mediaNode[error])">
            <img src="/ImageGen.ashx?image={$mediaNode/umbracoFile}&amp;width=100&amp;height=100" />
        </xsl:if>
    </xsl:if>
    
    (Highlighted the changed line)

     

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 20, 2012 @ 22:21
    Chriztian Steinmeier
    0

    Aha - so are you using an Media Picker or an Upload datatype for the previewImage property?

    /Chriztian

  • Damon Bauer 48 posts 95 karma points
    Nov 20, 2012 @ 22:25
    Damon Bauer
    0

    Media Picker. Sorry - I should have made it more clear than I did in my original post.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 20, 2012 @ 22:34
    Chriztian Steinmeier
    0

    Okay - well then everything is working and we can go home :-)

    Except it isn't, for some weird reason :-(

    Well, let's see - which version of Umbraco are you using? The last one I posted should work for any version above 4.5.2 (assuming everything is spelled and cased correctly).

    Only other reason I can see that code fail, would be if you have a previewImage property on any node below $currentPage with some bogus value in it (as in -31 or something greater than the limit of an Int32) ?

    /Chriztian

  • Damon Bauer 48 posts 95 karma points
    Nov 20, 2012 @ 22:40
    Damon Bauer
    0

    Ha! :) Using Umbraco v 4.9.0, Assembly version 1.0.4633.18696, on IIS 7, running on MySQL (yeek). 

    I'm just trying to select a normal PNG image. Also, the "$currentPage" never has a child node under it.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 20, 2012 @ 22:57
    Chriztian Steinmeier
    1

    Okay - this will be my 1600th post here, so bear with me if I go all Academy Awards ... :-)

    (YAY!)

    I honestly can't think of a reason why this doesn't work...

    Maybe you could try this instead of all the image code in the loop, and see if you can get any meaningful info about where it goes wrong?:

    <div>
        <div>Node: <xsl:value-of select="@nodeName" /></div>
        <div>Has <code>previewImage</code>: <xsl:value-of select="boolean(self::*[previewImage])" /></div>
        <div><code>previewImage</code>: <xsl:value-of select="previewImage" /></div>
        <div>
            <code>previewImage XML?</code>
            <textarea rows="8" cols="40"><xsl:copy-of select="previewImage" /></textarea>
        </div>
        <hr />
    </div>
    
    (Nothing wrong with MySQL - I run loads of Umbraco sites on that with no problems :-)

    /Chriztian

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 20, 2012 @ 23:12
    Jan Skovgaard
    0

    @Chriztian congrats on the achievement - keep'em coming sir! :)

    In regard to the comment about MySQL this is as Chriztian says fully supported by Umbraco. However you should be aware that some packages for Umbraco are not neccesarily build with MySQL support in mind. But most of the time it's not an issue but it of course depends on the solution you're building etc.

    Just my 2 cents.

    /Jan

  • Damon Bauer 48 posts 95 karma points
    Nov 20, 2012 @ 23:20
    Damon Bauer
    0

    Congrats on 1600! :)

    I implemented your code - nice trick by the way! That will definitely be useful at some point I'm sure. BUT - all of code returned is good.

    Even if I don't reference the image with imagegen, and instead use:

    <img src="{umbraco.library:GetMedia(./previewImage, 0)}" />

    I STILL get the System.OverflowException: Value was either too large or too small for an Int32. error message...

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 20, 2012 @ 23:27
    Chriztian Steinmeier
    0

    When you say "all [...] code returned is good", what do you mean by that?

    Did you get XML in the previewImage XML? fields?

    Did you get any negative values for previewImage ID?

    Any unusually large values?

    (Just checking)

    /Chriztian

  • Damon Bauer 48 posts 95 karma points
    Nov 20, 2012 @ 23:30
    Damon Bauer
    0

    Chriztian - sorry about that. Here's a sample of what I get:

    Node: Motorola Citrus
    Has previewImage: true
    previewImage: 1241
    previewImage XML?
    1241 

    Also, I found if I don't use select="umbraco.library:GetMedia(./previewImage, 0)", and instead use select="umbraco.library:GetMedia($currentPage/previewImage, 0)", I don't get the error, but I don't get the image either.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 21, 2012 @ 00:07
    Chriztian Steinmeier
    0

    This is indeed very strange Damon...

    The error is totally happening because somewhere among the nodes you're rendering, there's one with a serious attitude problem... and it doesn't make sense to me...

    Could you try rendering, say, 10 images at a time? E.g. in the initial test before the image stuff:

    <xsl:if test="normalize-space(previewImage) and position() &lt; 10">

    - and then increasing the number until the error appears?

    /Chriztian

     

  • Damon Bauer 48 posts 95 karma points
    Nov 21, 2012 @ 00:22
    Damon Bauer
    0

    Chriztian -

    Not totally sure what I should be doing with that last snippet.

    I found this code snippet (I know this is old schema, but I'm grasping at straws, and it DOESN'T produce an error):

     <xsl:if test="string(data [@alias = 'previewImage']) != ''">
                    <img src="/imagegen.ashx?image={umbraco.library:GetMedia(number(data [@alias = 'previewImage']), 'false')/data [@alias = 'umbracoFile']}&amp;width=250" alt="{@nodeName}" />
    </xsl:if>
     

    I fired up Chrome inspector tools, and I'm getting the following error:

    http://.../media/13543/lion%20avatar.jpeg80804294jpeg 404 (Not Found)

  • Damon Bauer 48 posts 95 karma points
    Nov 21, 2012 @ 00:31
    Damon Bauer
    0

    FINALLY! In a desperate attempt, I changed my initial line from:

    select="$currentPage/descendant::*[@isDoc]"> 

    to:

    select="$currentPage/* [@isDoc]">

    and it started working. I can't believe I missed this.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 21, 2012 @ 00:41
    Chriztian Steinmeier
    0

    Hi Damon,

    It doesn't make sense to me at all - are you telling me that you're actually using the old Schema? 'Coz that doesn't make sense with the last one (changing from descendant:: to child).

    And if you're not using the old schema, then you shouldn't even be getting image data in your Chrome debug output there...

    I'm actually pretty baffled - but when everything works, please post the XSLT and I'll do the sane "So the reason *this* line didn't work..." etc., for everyone else that lands on this in the future :-)

    /Chriztian

  • Damon Bauer 48 posts 95 karma points
    Nov 21, 2012 @ 03:24
    Damon Bauer
    0

    This is my code that seems to be doing what I want:

     

Please Sign in or register to post replies

Write your reply to:

Draft