Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 936 posts 2571 karma points
    Jan 18, 2017 @ 15:08
    Claushingebjerg
    0

    simple fixed width crop with imagecropper

    Ok, this should be simple, but i cant figure it out, and i think the docs are lacking on specifics.

    Im trying to do simple image resizing using the cropper, so i just want an image from the cropper, that has a fixed width, eg. 300 pixels.

    <img src="@Umbraco.Media(item.GetPropertyValue("billede")).GetCropUrl("galleri")" />
    

    This gives me a crop from a named crop definition. But what if i just want the image to be 300 pixels wide? or if i want a 300x300 image? its described in the docs, but unfortunately not clear enough for me to get it...

    https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/image-cropper

    Any help?

  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Jan 19, 2017 @ 16:37
    Paul Seal
    100

    Hi Claushingebjerg You could just do it yourself like this:

    <img src="@Umbraco.Media(item.GetPropertyValue("billede")).Url?width=300&height=300&mode=crop&anchor=center" />
    

    I hope this helps.

    Kind regards

    Paul

  • Kevin Jump 2311 posts 14697 karma points MVP 7x c-trib
    Jan 19, 2017 @ 17:45
    Kevin Jump
    0

    Hi

    based on teh documentation (assuming you are using Umbraco 7.3.5 or greater)

    you want

    @Url.GetCropUrl(Model.Content, propertyAlias: "billede", width: 300, height: 300)
    

    I would caution against nesting GetPropertyValues within other calls just because if they are null - you are going to get errors within your code.

    the above passes everything to the handler, so it can deal with things when you don't have values set. but just to be sure i personally would wrap this with a check

    if (Model.Content.HasProperty("billede") && Model.Content.HasValue("billeded") )
    

    then i know i have a value - and its set to something.

Please Sign in or register to post replies

Write your reply to:

Draft