Copied to clipboard

Flag this post as spam?

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


  • Martin Rud 261 posts 1002 karma points c-trib
    Jun 01, 2021 @ 12:11
    Martin Rud
    0

    The name 'ImageCropMode' does not exist in the current context

    I want to play with ImageCropMode in method GetCropUrl() so I added:

    @using Umbraco.Web.Models;
    

    And changed:

    image.GetCropUrl(100, 100)  
    

    (works)

    to ("Max" is just an example mode):

    image.GetCropUrl(100, 100, imageCropMode:ImageCropMode.Max)  
    

    (gives error)

    I get this error:

    CS0103: The name 'ImageCropMode' does not exist in the current context
    

    What do I need to do?

    The problem I am trying solve is: After going from calling image url directly (/media/xxxx/image.jpg?width=100&height=100) to now using GetCropUrl() a lot of images have some black padding arround them. This only goes away if I go to every single image in the backend, moves the focalpoint and saves.

    See example photo below:

    enter image description here

  • Brendan Rice 538 posts 1102 karma points
    Jun 01, 2021 @ 13:52
    Brendan Rice
    100

    Hey Martin,

    It seems like you're missing a reference, put this at the top of the cshtml:

    @using Umbraco.Web.Models
    

    Then you should be able to get the crop URL like this:

    var test = yourImage.PreviewImage.GetCropUrl(30, 30, imageCropMode: ImageCropMode.Max);
    
  • Martin Rud 261 posts 1002 karma points c-trib
    Jun 01, 2021 @ 16:34
    Martin Rud
    1

    My bad!!!! 🙄

    I wrote that I had added

    @using Umbraco.Web.Models
    

    ... but checking my code again I see that I actually forgot...

    Thanks! :)

Please Sign in or register to post replies

Write your reply to:

Draft