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
    Feb 03, 2016 @ 14:31
    Claushingebjerg
    0

    Get crop with width and height using TypeMedia

    So, i have

    @{
        var mediaItem = Umbraco.TypedMedia(1236);
        if (mediaItem != null)
        {
            <img src="@Url.GetCropUrl(mediaItem, height: 300, width: 400)" />
        }
    }
    

    doesnt work... Any help :)?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Feb 03, 2016 @ 14:34
    Jeavon Leopold
    0

    What does that return?

  • Claushingebjerg 936 posts 2571 karma points
    Feb 03, 2016 @ 14:37
    Claushingebjerg
    0

    error CS1928: 'System.Web.Mvc.UrlHelper' does not contain a definition for 'GetCropUrl' and the best extension method overload 'Umbraco.Web.HtmlHelperRenderExtensions.GetCropUrl(System.Web.Mvc.HtmlHelper, Umbraco.Core.Models.IPublishedContent, int?, int?, string, string, int?, Umbraco.Web.Models.ImageCropMode?, Umbraco.Web.Models.ImageCropAnchor?, bool, bool, bool, string, Umbraco.Web.Models.ImageCropRatioMode?, bool)' has some invalid arguments

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Feb 03, 2016 @ 14:38
    Dennis Aaen
    1

    Hi Claus,

    Have you tried something like this where the image is the property alias of the cropper property

    @if (mediaItem.HasValue("image"))
    {
        <img src="@Url.GetCropUrl(mediaItem, propertyAlias: "image", height: 300, width: 400)" />
    }
    

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

    By the way are you using Umbraco 7.3.5 or a newer version?

    Hope this helps,

    /Dennis

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Feb 03, 2016 @ 14:41
    Jeavon Leopold
    0

    Yes, I think maybe you are using pre v7.3.5?

  • Claushingebjerg 936 posts 2571 karma points
    Feb 03, 2016 @ 14:44
    Claushingebjerg
    0

    The problem is im inside a "Nested content" in a "Leblender" and aparrently that kills "propertyalias".

    What i am looking really for is a way to get a integer valued crop from an image id.

    I have the image id. I want a crop thats eg: 300x300 pixles.

    im on 7.3.4

  • Claushingebjerg 936 posts 2571 karma points
    Feb 03, 2016 @ 14:51
    Claushingebjerg
    0
    @Umbraco.TypedMedia(1236).GetCropUrl(height: 100, width: 600)
    

    Success!

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Feb 03, 2016 @ 15:00
    Jeavon Leopold
    1

    Cool, Url helper is new in v7.3.5 onwards

Please Sign in or register to post replies

Write your reply to:

Draft