Copied to clipboard

Flag this post as spam?

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


  • Perry Cope 31 posts 195 karma points
    Dec 20, 2022 @ 17:42
    Perry Cope
    0

    GetCropUrl No longer works with local images

    In Umbraco 8 GetCropUrl could be used with a string of the images path not just the publishedcontentmodel

    var imageUrl = Model.Image.Url() ?? "/images/logos/fallback-image.png";
    @Url.GetCropUrl(imageUrl, 600, 500, imageCropperValue: bannerCrop, cacheBusterValue: cacheKey)
    

    Before if an image was not set in the CMS we could fallback to a local Image in the source code and then also crop it I can no longer get this to work in Umbraco 11. I have also tried this.

    var imageUrl = Model.Value<IPublishedContent>("image",fallback: Fallback.ToDefaultValue, defaultValue: "/images/logos/fallback-logo.png");
    
  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Dec 21, 2022 @ 11:30
    Marc Goodson
    100

    Hi Perry

    Yes, it looks like some of the usual UrlHelpers got waylaid in the move to .net core.

    using Url.GetCropUrl was always the suggested new 'best way' to replace using GetCropUrl extension methods that existed on IPublishedContent or the string...

    ... ironically it looks like the older approach has been moved across to .net core, under the guise of the FriendlyImageCropperTemplateExtensions:

    https://github.com/umbraco/Umbraco-CMS/blob/5ef43cb4f043e4d6910c213972bc68ba7c068ceb/src/Umbraco.Web.Common/Extensions/FriendlyImageCropperTemplateExtensions.cs

    So if you have an @using Umbraco.Extensions in your template you should be able to write

    var imageUrl = Model.Image.Url() ?? "/images/logos/fallback-image.png";
    @imageUrl.GetCropUrl(600, 500, imageCropperValue: bannerCrop, cacheBusterValue: cacheKey)
    

    But agree it would be good to get the Extension methods added to UrlHelper, so you could write the same Url.GetCropUrl and pass in a string, maybe there was a reason to remove them, this commit

    https://github.com/umbraco/Umbraco-CMS/commit/6d97cbd95471acb1081bc710aa3e3fa77301537b

    seems to show they might have just been missed.

    regards

    Marc

  • Perry Cope 31 posts 195 karma points
    Dec 21, 2022 @ 15:08
    Perry Cope
    0

    Ah woops i should have noticed that.

    i guess i've got a lot of refactoring to do I think i will open a Github ticket too to see if it can come back.

Please Sign in or register to post replies

Write your reply to:

Draft