Copied to clipboard

Flag this post as spam?

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


  • Gísli Freyr Svavarsson 43 posts 126 karma points
    Jun 04, 2014 @ 15:34
    Gísli Freyr Svavarsson
    0

    Getting Image Crop from media-picker file

    Hi there, 

    I've been trying to find a way to get the crop urls  from a media-picker file. 

    here is my code that displays the "topImage" from the media picker, what do I have to add to get a specific crop?

     

    @{
    if (Model.Content.HasValue("topImage", true))
    {
    var mediaItem = Umbraco.TypedMedia(Model.Content.GetPropertyValue("topImage", true));
    <img src="@mediaItem.GetPropertyValue("umbracoFile")" alt="@mediaItem.GetPropertyValue("Name")" />
    }
    }

    I've been google-ing for hours without finding exactly what i need.

    mvh

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 04, 2014 @ 15:40
    Jeavon Leopold
    0

    Hey, check out last weeks uHangOut where I went through the cropper in detail. You can find the example site used in uHangOut here Specifically what you are looking for is here

  • Gísli Freyr Svavarsson 43 posts 126 karma points
    Jun 04, 2014 @ 16:53
    Gísli Freyr Svavarsson
    0

    Thanks Jeavon, 

    Does that also work for Umbraco 6.1.6 ?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 04, 2014 @ 16:59
    Jeavon Leopold
    100

    Ah no, for v6 you should take a look at the documentation here

    However I would recommend also taking a look at CropUp which is the inspiration behind the v7 cropper

  • Gísli Freyr Svavarsson 43 posts 126 karma points
    Jun 05, 2014 @ 16:58
    Gísli Freyr Svavarsson
    0

    Thanks Jeavon, 

    I ended up using the CropUp as I couldn't get the normal cropper to work. 

     

    This then worked for me. 

    @{
    if (Model.Content.HasValue("topImage", true)) {
    var mediaItem = Umbraco.TypedMedia(Model.Content.GetPropertyValue("topImage", true));
    var newURL = @mediaItem.GetPropertyValue("umbracoFile");
    <img src="@CropUp.GetUrl(newURL.ToString(), new ImageSizeArguments { Width = 960, Height = 201 })" />
    }
    }

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 05, 2014 @ 17:02
    Jeavon Leopold
    0

    Great, CropUp is definitely the best cropping solution for v6 projects.

Please Sign in or register to post replies

Write your reply to:

Draft