Copied to clipboard

Flag this post as spam?

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


  • Linx 98 posts 258 karma points
    Dec 16, 2023 @ 14:35
    Linx
    0

    GetCropUrl not working after recent upgrade

    Hi

    I installed Umbraco 10.8.2 and created a Doc Type with an Image Cropper by creating a new Data Type. The new version is the same as the original but has additional aliases with different dimensions.

    I upload an image via the content section and have the below code in my view

    @Model.MyImage.GetCropUrl("DimensionName");
    

    but this doesnt compile. I then tried different variations such as

    @Model.MyImage.GetCropUrl("myImage", "DimensionName");
    

    but none seem to work or i get the full image and not the cropped image.

    Whats gone wrong?

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Dec 18, 2023 @ 17:36
    Steve Morgan
    0

    Are you sure this is an upgrade issue?

    I wonder if it's how you're using Razor.

    The @ puts Razor into "code mode" - it doesn't require semi colons (like normal c#) but it does need to know where it begins and it ends.

    The safest way to do this inline, where there are parenthesis in the code segment, is to wrap the whole statement in parenthesis.

    Try:

    @(Model.MyImage.GetCropUrl("dimensionName"))
    

    So if it's in an image tag:

    <img src="@(Model.MyImage.GetCropUrl("dimensionName"))" class"myclass"/>
    

    Also note above I've assumed your alias for your crop actually starts with a lowercase letter. Check your crop - it will be case-sensitive.

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Dec 18, 2023 @ 17:37
    Steve Morgan
    0

    If the above doesn't work then if there is an exception post the error here and it will give up the issue.

  • Linx 98 posts 258 karma points
    Dec 19, 2023 @ 10:59
    Linx
    0

    Hi

    I tried that but when i copied the code above i left it from a code block.

    When i try

    @Model.MyImage.GetCropUrl("DimensionName")
    

    The error i receive is

    Error (active) CS1501 No overload for method 'GetCropUrl' takes 1 arguments

    All the documents and examples ive seen seem to use the above. I also tried

    @Model.MyImage.GetCropUrl("myImage", "DimensionName")
    

    but then i receive

    CS1503 Argument 2: cannot convert from 'string' to 'Umbraco.Cms.Core.Media.IImageUrlGenerator'

  • Linx 98 posts 258 karma points
    Dec 21, 2023 @ 15:48
    Linx
    0

    Does anyone have any idea? I cant tell if im doing something wrong or if im missing something?

  • Brendan Rice 538 posts 1102 karma points
    Dec 21, 2023 @ 17:47
    Brendan Rice
    0

    That error could suggest you haven’t imported Umbraco extension namespace at the top of the view.

    @using Umbraco.Extensions
    
  • Linx 98 posts 258 karma points
    Dec 22, 2023 @ 10:36
    Linx
    0

    Sorry that too made no difference

    With or without that using statement the same error occurred

    enter image description here

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Dec 29, 2023 @ 09:33
    Steve Morgan
    100

    I think you've created a document type property of "Image Cropper" - this is supplying to the view a "ImageCropperValue".

    You'll notice that the documentation is talking about MediaWithCrops - this has the extension methods you're expecting that will allow you to pass in the single crop alias. ImageCropperValue won't.

    https://docs.umbraco.com/umbraco-cms/v/10.latest-lts/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/image-cropper

    Though what you've done is rendering a picker picker in the back office and looks correct I think you'd find it much easier to change to using a "Media Picker".

    So the fix is to go to your doc type - add a new property - choose type Media Picker (create new) - then add your crops here.

    You'll find the Media Picker v3 much easier to get working. I think what you have is a bit of backwards compatibility legacy. There used to be a helper on Url.GetCropUrl() that made these image croppers work in the doc type but that's missing now I believe.

    As the Media Picker is more a v13 way of going I'd do this.

Please Sign in or register to post replies

Write your reply to:

Draft