Copied to clipboard

Flag this post as spam?

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


  • Jon 47 posts 290 karma points
    Jan 30, 2017 @ 19:19
    Jon
    0

    Get cropped image

    I'm having problems getting the image url to the croppede image:

    style="background-image: url(@Url.GetCropUrl(Model.Content, "billede", "ImageCrop.Thumb"))"
    

    It returns:

    style="background-image: url(1055?mode=pad&rnd=131302645130000000)"
    

    What am I missing?

    Umbraco 7.5.7

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jan 30, 2017 @ 20:38
    Alex Skrypnyk
    0

    Hi Jon

    Try to use strongly typed way, I think code should be like that:

    @{
        var mediaItem = Umbraco.TypedMedia(Model.Content);
        if (mediaItem != null)
        {
            <img src="@Url.GetCropUrl(mediaItem, "ImageCrop.Thumb")" />
        }
    }
    

    Thanks,

    Alex

  • Jon 47 posts 290 karma points
    Jan 30, 2017 @ 23:22
    Jon
    0

    Hi Alex

    Thank you for your answer! Unfortunately there where no luck.

    My image field is call: billede My crop (ImageCrop) has 3 sizes: Hero, Teaser and Thumb.

    If I call the image by id - theres no problem...

    background-image: url(@Umbraco.Media(1055).GetCropUrl("hero"))
    

    But I need it to be dynamic

  • Matt W 8 posts 28 karma points
    Jan 31, 2017 @ 09:22
    Matt W
    0

    I think you need something like this. Works for me....

    <img style="background-image" src="@CurrentPage.GetCropUrl("PropertyAliasHere", "WhateverYouHaveCalledTheCropHere")" />
    
Please Sign in or register to post replies

Write your reply to:

Draft