Copied to clipboard

Flag this post as spam?

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


  • Kim Nedergaard 37 posts 144 karma points
    Aug 18, 2014 @ 13:47
    Kim Nedergaard
    0

    Image Cropper - Razor and how to verify

    Hi there,

    I'm using the Image Cropper in an Umbraco 7.1.4 installation.

    I've used the umbracoFile alias on the Image media-type. So instead of the standard upload field are we now using the Image Cropper.

    The website has been running some time without the Image Cropper - so there are alot of images that are created through the standard uploadfield.

    So now I need to check whether the image has been saved with the image cropper datatype embedded or not. Otherwise I'll have to manually save ALL images, so all the images returns the Image Cropper JSON in the umbracofield.

    I've made a quick fix:

    if(slider.GetPropertyValue("bodyMedia") != null){
     var mediaItem = Umbraco.Media(slider.GetPropertyValue("bodyMedia"));                           var imagePath = mediaItem.umbracoFile;
    
     try
     {
      imagePath = mediaItem.GetPropertyValue("umbracoFile").src;
     }
     catch (Exception ex)     
     {
      imagePath = mediaItem.GetPropertyValue("umbracoFile");
     }
    }
    

    And in XSLT I've solved it by doing the following:

    <xsl:variable name="image" select="umbraco.library:GetMedia($imageSource,'true')"/>
    <xsl:variable name="imageJSONToXML" select="umbraco.library:JsonToXml($image/umbracoFile)"/>
    
    <xsl:variable name="imagePath">        
     <xsl:choose>
      <xsl:when test="$imageJSONToXML/src != ''">
         <xsl:value-of select="$imageJSONToXML/src"/>        
       </xsl:when>
       <xsl:otherwise>
            <xsl:value-of select="$image/umbracoFile"/>
       </xsl:otherwise>
      </xsl:choose>                  
     </xsl:variable>
    

    Thank you for your time.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 18, 2014 @ 13:56
    Jeavon Leopold
    1

    Interesting, I have been working on a healing helper which will populate with default cropper JSON when a GetCropUrl method is requested for a cropper but the JSON is missing. I'm planning on adding it to Slimsy but it could be used elsewhere as well. I'll keep you posted with progress :-)

Please Sign in or register to post replies

Write your reply to:

Draft