Copied to clipboard

Flag this post as spam?

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


  • David Houghton 33 posts 108 karma points
    May 25, 2017 @ 10:26
    David Houghton
    0

    Cannot get crop url of image using 7.6

    How do you get the crop url of a single image in umbraco 7.6, it seems typedMedia no longer works.

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    May 25, 2017 @ 10:29
    Alex Skrypnyk
    0

    Hi David

    Try this code:

    var cropUrl = Udi.Parse("mediaUDI").ToPublishedContent().GetCropUrl("cropAlias");
    

    Can you show your razor code? Maybe we will fix it together with the community.

    Alex

  • David Houghton 33 posts 108 karma points
    May 25, 2017 @ 10:34
    David Houghton
    0

    This is the old way id get images using Umbraco.TypedMedia

    Check the Model has a property and that property has a value

        var bgAlias = "backgroundImage";
        var hasImage = Model.Content.HasProperty(bgAlias) && Model.Content.HasValue(bgAlias);
        var image = String.Empty;
    

    Then check the image exists using the returned ID and if so then return the crop url into image, which is initially set to an empty string...

    if (hasImage)
    {
       var imageNode = Umbraco.TypedMedia(Model.Content.GetPropertyValue(bgAlias));
    
       if(imagenode != null){
            image = imageNode.getCropUrl("cropAlias")
       }
    }
    
  • David Houghton 33 posts 108 karma points
    May 25, 2017 @ 10:45
    David Houghton
    1

    Ive also tried the provided examples from - https://our.umbraco.org/documentation/getting-started/design/Rendering-Media/

    and using like for like, but passing my own values like so:

    var mediaItem = Umbraco.Media(Model.Content.GetPropertyValue(bgAlias));
    var croppedUrl = Url.GetCropUrl(mediaItem, "largeHeader");
    

    enter image description here

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    May 25, 2017 @ 10:53
    Alex Skrypnyk
    2

    David, this code works for me:

    var bgAlias = "backgroundImage";
    var hasImage = Model.Content.HasProperty(bgAlias) && Model.Content.HasValue(bgAlias);
    var image = String.Empty;
    if (hasImage)
    {
        var imageNode = Model.Content.GetPropertyValue<IPublishedContent>(bgAlias);
    
        if(imageNode != null)
        {
            image = imageNode.GetCropUrl("largeHeader");
        }
    }
    
  • David Houghton 33 posts 108 karma points
    May 25, 2017 @ 11:03
    David Houghton
    0

    Thanks Alex, life saver.

    Can I ask why this version has been changed this way and why support for TypedMedia seems to be removed.

    Im sure there is a decent reason why, but please appreciate that for us using this platform day-to-day its very frustrating when all of a sudden methods that we have been using a certain way for so long just cease to function as they used to with little to no documentation.

    Im sure there is something im misunderstanding or missing, but all I can tell you is a job that should have taken me at most 10 mins to do, has become this long forum thread asking for help taking me to well over an hour for something that is basic work within the cms, just getting an image.

    Very frustrating as I hope you can appreciate and im sure many other developers can relate to.

Please Sign in or register to post replies

Write your reply to:

Draft