Copied to clipboard

Flag this post as spam?

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


  • Frederik T 234 posts 345 karma points
    Aug 22, 2011 @ 10:41
    Frederik T
    0

    Using imagegen with DAMP classic

    Ok, this might be an overly retarded question, but i just cant get imagegen to output a damp-classic image. it SHOULD be the same as just an ordinary image but i just cant get it working.

    So, how do i do it? the alias for the property is "vp-thumb", if that helps, if more information is needed, please ask.

    Also, i think a code snippet is uneeded as its pretty straightforward i guess, its just me that might have overlooked something.

  • Rich Green 2246 posts 4008 karma points
    Aug 22, 2011 @ 11:07
    Rich Green
    0

    What does your HTML output?

    Rich

  • Frederik T 234 posts 345 karma points
    Aug 22, 2011 @ 11:20
    Frederik T
    0

    I cant get HTML output, because it doesnt work, here is the code if you want, but its pretty useless...:

    <img class="vpSliderImg" src="/ImageGen.ashx?image={umbraco.library:GetMedia(vp-SliderPicture/classic, 0)/umbracoFile}&width=425&height=250&constrain=false"/>

    ("vp-SliderPicture" is the alias for another picture that is also damp classic, but it was the only code snippet i had of it in use and also i apologize for the poor formatting, posting doesnt work very well right now)

    That above gives a int32 buffer overflow exception but i knew it was wrong to begin with i just kept experimenting until i hit something that worked, because i have no idea how it works to begin with...

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Aug 22, 2011 @ 11:51
    Douglas Robar
    0

    Hi, Frederik,

    We will need to step back and take this one step at a time.

    1. Do you have an <img> tag that works with the vp-Thumb property at all? One that doesn't try to use ImageGen but only outputs the vp-Thumb itself.

    Can you show us that line of XSLT? This is the first step; get the DAMP image to appear.

    2. Once you have the above, please double-check that you have ImageGen installed properly. What output do you get when you visit /imagegen.ashx?version on your site?

    3. Now that you have good XSLT for the DAMP image and you know ImageGen is functioning properly it is a fairly simple matter to use them together. First, add /imagegen.ashx?image= at the start of your src= tag. ImageGen won't resize the image but will return it at the original size just as if you hadn't included ImageGen. When that works, you can start adding parameters to the ImageGen command for width, height, etc.

    Be sure that when you use the '&' character in XSLT that you always escape it to '&amp;' because that's a requirement of XSLT. In otherwords, in an XSLT macro in order to get &width=425&height=250 you'd write &amp;width=425&amp;height=250.

    Let us know what you find out.

    cheers,
    doug. 

     

  • Frederik T 234 posts 345 karma points
    Aug 22, 2011 @ 12:08
    Frederik T
    0

    Thank you for replying.

    No, i cant get it to output an image at all (yes its an img tag), i have a feeling that im using DAMP wrong. According to the DAMP sample xslt file, i can get the image like this:

    <img src="{umbraco.library:GetMedia($currentPage/classic, 0)/umbracoFile}" height="150px;" />

    But thats it. The document contains several damp classic properties, so i need to get one with a specific alias. I dont know how to tell it with that syntax to look for that specific file.

    Im sorry that this might be out of your field, i initially thought it had something to do with imagegen but it looks like that isnt the case. Sorry that you are going out of your way to help me.

    Also, ive been using imagegen with DAMP new with great success and that is working fine, and im very happy with imagegen in that regard as it saves us a lot of time creating several versions of the same picture.

  • Frederik T 234 posts 345 karma points
    Aug 22, 2011 @ 16:42
    Frederik T
    0

    Ok, finnaly got rid of that int32 bufferoverflow exception so i can now display the image without imagegen, yet. It was a very roundabout way so i will just post it here as an example, because apparently i had to put it in a loop before it wanted to cooperate. Which in my eyes isnt a correct solution.

     


    xsl:stylesheet [ ]>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:rdm="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="msxml msxsl umbraco.library rdm">
        <xsl:output method="xml" omit-xml-declaration="yes" />

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage" />
    <xsl:variable name="maxItems" select="number(5)" />
    <msxsl:script language="JavaScript" implements-prefix="rdm">
        function Random(r){return Math.random()}
    msxsl:script>
    <xsl:template match="/">

    <div class="g640p10" style="position:relative;">
       <h4><a href="/karriere/virksomhedsprofiler" title="Virksomhedsprofiler" class="purple">Virksomhedsprofilera>h4>
       <ul id="vpSlider">
       
      <xsl:for-each select="$currentPage/descendant::Virksomhedsprofil [@isDoc]">
        <xsl:sort select="rdm:Random($maxItems)" order="descending" />
        <xsl:if test="position() <= $maxItems">

        <li>
        <xsl:choose>
        <xsl:when test="current()/vp-SliderPicture != ''">
          <xsl:variable name="media" select="umbraco.library:GetMedia(current()/vp-SliderPicture, 'false')" />  
          <img class="vpSliderImg" src="{$media/umbracoFile}" width="425" height="250"/>
        xsl:when>
        <xsl:otherwise>
          <img class="vpSliderImg" src="/ImageGen.ashx?image={current()/outputPictures[position()=1]/DAMP[@fullMedia]/mediaItem/Image/umbracoFile}&width=425&height=250&constrain=false" />
        xsl:otherwise>
        xsl:choose>
          <img style="padding: 10px 0;" src="/ImageGen.ashx?image={current()/outputPictures[position()=1]/DAMP[@fullMedia]/mediaItem/Image/umbracoFile}&width=125&height=70&constrain=true" />
          <hr />
          <p><xsl:value-of select="vp-tekstTilSlider" />p>
          <p><a href="{umbraco.library:NiceUrl(@id)}" class="purple" title="Læs mere">
            <xsl:attribute name="title">Læs mere om <xsl:value-of select="vp-virksomhedsnavn" />xsl:attribute>
              Læs mere om <xsl:value-of select="vp-virksomhedsnavn" />a>p>
        li>
        
        xsl:if>
      xsl:for-each>
      ul>
      <div id="vpSliderPager"><xsl:value-of select="normalize-space('')"/>div>     
    div>

    xsl:template>
    xsl:stylesheet>
  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Aug 22, 2011 @ 17:26
    Douglas Robar
    0

    Ah, I think I know the root cause of the problem - the umbraco.library:GetMedia() call when you save the XSLT macro gives the Int32 error. This is a common frustration and can lead people down the wrong path to find a solution.

    Time for some background on how Umbraco works...

    When you save an XSLT macro Umbraco will compile it and test it against the first page in your content tree (typically that'll be the homepage). This will help find errors in the XSLT before you save it and then get errors at runtime on your site.

    The trouble is that sometimes the homepage is totally inappropriate to be the source page for the macro being saved and the macro would be just fine when run against the real content pages it is meant for. Worse, the umbraco.library:GetMedia() call will give that nasty Int32 error if the media item you're trying to get doesn't exist (rather than failing silently). Combine these two 'features' and you can get the behavior you described - you can't even save the xslt file without getting the Int32 error.

    There are two ways around this. The easy way is to tick the 'skip testing' checkbox before you save the XSLT. This will save the file but will not test it against the first page in your site. You won't get the benefit of any error checking but then again the file will save and you can run it on your site in the proper context and it may work just fine in that situation. You just have to remember to tick that box every time you want to save the xslt file.

    The second way is to put an <xsl:if> test around the code that has the GetMedia() call. Typically, whatever you have in your GetMedia() call is the same thing you'd put in the xsl:if. An example:

    Assume this gives an error:

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

    You'd put an xsl:if around it so that when the XSLT is saved it can still be tested but the test code won't process what's in the xsl:if block because when testing against the homepage it won't be valid (but it will be valid when run in its proper place in the website). Like this:

    <xsl:if test="string(someProperty/classic) != '' ">
    <img src="umbraco.library:GetMedia({someProperty/classic}, 0)" />
    </xsl:if>
    What you have in your elaborate example is a for-each loop with xsl:when conditions that serve the same purpose. But I bet you can simplify your macro dramatically now that you know this background info.
    Hope that helps.
    cheers,
    doug. 

     

  • Frederik T 234 posts 345 karma points
    Aug 23, 2011 @ 09:13
    Frederik T
    0

    I greatly appreciate that you will explain it to me in such detail, it will help me definetly help me in the future as reference. Its hard to find proper explanations to problems such as this.

    Im sorry that this ended up having nothing to do with imagegen, though i didnt anticipate that at first.

    I really wanted to optimize my code with your example above but that doesnt work either. It compiles fine, but no picture is shown.

    <xsl:if test="string(vp-SliderPicture/classic) != '' ">
          <img class="vpSliderImg" src="umbraco.library:GetMedia({vp-SliderPicture/classic}, 0)" width="425" height="250" />
          </xsl:if>

    Though its far from pretty, guess im stuck with using my ugly method for now.

    Well, if you leave this thread i understand that, this belongs in another sub-forum now, but i just wanted to put this last bit out there.

    Again, thank you for your time.

  • Frederik T 234 posts 345 karma points
    Sep 08, 2011 @ 15:28
    Frederik T
    0

    Sorry for bumping, i still cant get ImageGen to work with DAMP Classic, here is my current code:

    (the document it displays has two image properties. One DAMP New and one DAMP Classic. If one is empty it displays the other, and it works fine. The problem is that the DAMP Classic image is pretty big, hence why i want to use imagegen with it. How do i implement it in the snippet below? Because whatever i try doesnt work.

    <xsl:choose>
                  <xsl:when test="current()/vp-SliderPicture != ''">
                    <xsl:variable name="media" select="umbraco.library:GetMedia(current()/vp-SliderPicture, 0)" />  
                    <img src="{$media/umbracoFile}" width="220" height="130"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <img src="/ImageGen.ashx?image={current()/outputPictures[position()=1]/DAMP[@fullMedia]/mediaItem/Image/umbracoFile}&amp;width=220&amp;height=130&amp;constrain=false" width="220" height="130" />
                  </xsl:otherwise>
                </xsl:choose>

Please Sign in or register to post replies

Write your reply to:

Draft