Copied to clipboard

Flag this post as spam?

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


  • Trent Grandey 22 posts 143 karma points
    Dec 09, 2016 @ 07:08
    Trent Grandey
    0

    Problems with GetCropUrl on Media

    Using Umbraco version 7.5.4 assembly: 1.0.6136.27241

    Trying to get the GetCropUrl functionality working.

    I have a DocumentType that has a Media Picker. I am getting the media items from it and trying to get the cropper url for the items.

    I've run across many ways to use the cropper and just can't get the correct thing working.

    I can successfully get the media item:

    var image = Umbraco.Media(imageList[0]); This gets me image as "Umbraco.Web.Models.DynamicPublishedContent"

    If I then do @image.GetCropUrl(200,200) I just get nothing.

    I have tried @Url.GetCropUrl and get an error that the UrlHelper doesn't have a method named GetCropUrl.

    How is the best way to start with a media id and turn it into a crop url that respects the focal point and allows me to provide a width and height?

    Thanks,

    Trent

  • Fredrik Esseen 610 posts 906 karma points
    Dec 09, 2016 @ 07:29
    Fredrik Esseen
    100

    The way I do it (there might be better ways) is like this:

    In the media type Image add a crop size under the Image Cropper Mediatype. Give it a name and a width and height.

    Then:

    var m = Umbraco.Media(imageList[0]).GetCropUrl("theCrop");
    
    <img src="@m" />
    
  • Trent Grandey 22 posts 143 karma points
    Dec 09, 2016 @ 16:46
    Trent Grandey
    0

    This worked like a charm. Thank you!

  • John Lee 6 posts 116 karma points
    Dec 09, 2016 @ 10:13
    John Lee
    0

    I believe you need to use TypedMedia to get an IPublishedContent:

    var m = Umbraco.TypedMedia(imageList[0]).GetCropUrl(200, 200);
    
  • Trent Grandey 22 posts 143 karma points
    Dec 09, 2016 @ 16:48
    Trent Grandey
    0

    I was trying to use this syntax. Without having to create the predefined crops in the editor. But I never could get it to return anything. I tried both Media and Typed media and just kept drawing blanks. But predefining the crops made it work, so I can move on.

    Thank you for your response, though. I really think this should work, but I must be missing something.

Please Sign in or register to post replies

Write your reply to:

Draft