Copied to clipboard

Flag this post as spam?

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


  • Thomas Kahn 602 posts 506 karma points
    Oct 13, 2011 @ 16:21
    Thomas Kahn
    0

    Getting the crop URL from an image that is cropped in Media, not on a page, using razor?

    Hi!

    I have put and Image Cropper on the image media type so I can create cropped versions of the images I upload in the media section. On my pages I have a Media Picker where you can pick an image from the media section. All this works fine, but I can't figure out how to get a cropped version of the image I've picked.

    This is the farthest I've come so far:

    @node.Media("blogPostImage""imageCrops")
    

    In the example above @node is the current node (page) in a foreach iteration. All nodes that are iterated have a media picker property called "blogPostImage". All images in the image archive have an image cropper property called "imageCrops". The result I get when I run the code above is this:

    <crops date="13/10/2011 14:46:58"><crop name="Liggande bild" 
    x="0" y="43" x2="995" y2="470" url="/media/583/lighthouse_Liggande 
    bild.jpg" /><crop name="Stående bild" x="0" y="0" x2="457" 
    y2="515" url="/media/583/lighthouse_Stående bild.jpg" 
    /></crops> 

    Now I want the url of one of the crops, in the example above it's called "Liggande bild" (panorama image in Swedish).

    Sifting through the forum and the web there are lot's of suggestions and examples, but most of them are not relevant in this case since they are either based on DAMP 2.0 or are for cases when the image is uploaded and cropped on the page.

    I've seen some examples where people use helper functions, but I can't seem to get that to work.

    I'd really appreciate some help with this one!

    Regards,
    Thomas Kahn

  • Thomas Kahn 602 posts 506 karma points
    Oct 14, 2011 @ 09:46
    Thomas Kahn
    0

    Never mind.

    I'm reverting to XSLT.

  • Biagio Paruolo 1618 posts 1910 karma points c-trib
    Sep 10, 2012 @ 15:22
    Biagio Paruolo
    0

    How Do you do?

  • Thomas Kahn 602 posts 506 karma points
    Sep 10, 2012 @ 16:02
    Thomas Kahn
    0

    Oh, hi! 

    This was ages ago so I had to sift through some old code to find the XSLT-based solution that I finally settled for:

    <img class="landscape">
    <xsl:attribute name="src">
    <xsl:value-of select="$item/panoramaImage/DAMP/mediaItem/Image/imageCrops/crops/crop[@name='liggandeBild']/@url"/>
    </xsl:attribute>
    <xsl:attribute name="alt">
    <xsl:value-of select="$item/panoramaImage/DAMP/mediaItem/Image/altTag"/>
    </xsl:attribute>
    </img>

    This works fine in my solution. The variable $item is a node that comes from a for-each loop.

  • Biagio Paruolo 1618 posts 1910 karma points c-trib
    Sep 10, 2012 @ 17:28
    Biagio Paruolo
    0

    Thank, but I need for Razor.

Please Sign in or register to post replies

Write your reply to:

Draft