Copied to clipboard

Flag this post as spam?

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


  • RunnicFusion 62 posts 145 karma points
    Apr 24, 2014 @ 12:35
    RunnicFusion
    0

    ImageCropper ImageCropMode doesn't work

    Hi,

    For a Umbraco 7.1 website i'm using the image cropper to crop gallery images.

    My thumbnails works but when i click an image the image will be scalled bigger than the width of the image.

    the code i'm using:

    var largeImagePath = mediaChild.GetCropUrl(height: bigHeight, imageCropMode: ImageCropMode.Pad);
    

    At the blog i've read that i need to use the ImageCropMode but when is set this to max it doens't work. The url still will be using the crop mode.

    The problem is that i'm using not a width, only an height. With both specified the crops works but i only have the height because the images are not all the same width.

    How to get this working?

    reference: http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/50182-Change-ImageCropMode-with-ImageCropper-has-no-effect

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 24, 2014 @ 12:48
    Jeavon Leopold
    0

    Hi Roy,

    Can I just clarify a couple of things,

    1. mediaChild has a cropper editor on the alias "umbracoFile"?
    2. You want to get the image at a certain height but with the width being varied depending on source?

    Assuming the above, did you try the solution in the other post?

    @using Newtonsoft.Json
    @using Umbraco.Web.Models
    var imageCrops = JsonConvert.DeserializeObject<ImageCropDataSet>(mediaChild.GetPropertyValue<string>("umbracoFile"));
    var largeImagePath = imageCrops.Src.GetCropUrl(height:bigHeight, imageCropMode:ImageCropMode.Pad);
    
    <img src="@largeImagePath " />
    

    Jeavon

  • RunnicFusion 62 posts 145 karma points
    Apr 24, 2014 @ 13:14
    RunnicFusion
    0

    Hi Jeavon,

    mediaChild has a cropper editor on the alias "umbracoFile"? You want to get the image at a certain height but with the width being varied depending on source?

    yes the cropper has the alias umbracoFile. yes that is correct. i want to load images from different sizes but with a max height of 600 px.

    The code i've been using: (the mediaChild where the GetCropUrl is at is a media item)

    var largeImagePath = mediaChild.GetCropUrl(height: bigHeight, imageCropMode: ImageCropMode.Pad);
                            if (imageItem.HasValue("umbracoFile"))
                            {
                                <li>
                                    <a href="@largeImagePath" title="@mediaChild.Name" class="@uniqueName">
                                        <img src="@smallImagePath" alt="@mediaChild.Name" />
                                    </a>
                                </li>
                            }
    
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 24, 2014 @ 13:23
    Jeavon Leopold
    0

    Ok, I think the above should work for you then?

  • RunnicFusion 62 posts 145 karma points
    Apr 24, 2014 @ 13:29
    RunnicFusion
    0

    Ok, I think the above should work for you then?

    Te above will work when i specify the height AND width, not just height or weight. So in my situation it only takes the crop, but i want it to have a max width for scaling

    example:

    - image 1: 400 height, 300 width
    - image 2: 100 height, 100 width
    
    crop has max width of 200
    image 1: 400 height, 200 width  
    image 2: 100 height 100 width (in my code this is smaller than the crop so it will be streched)
    
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 24, 2014 @ 14:30
    Jeavon Leopold
    0

    Try this:

    var imageCrops = JsonConvert.DeserializeObject<ImageCropDataSet>(mediaChild.GetPropertyValue<string>("umbracoFile"));
    var largeImagePath = imageCrops.Src.GetCropUrl(height: bigHeight, imageCropMode: ImageCropMode.Max);
    

    Make sure you have the following @usings at the top

    @using Newtonsoft.Json
    @using Umbraco.Web.Models
    
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 13, 2014 @ 21:49
    Jeavon Leopold
    0

    FYI, I fixed this in Umbraco v7.1.2 so now if you specify a mode other than crop it doesn't crop

  • Nora 28 posts 97 karma points
    Sep 26, 2016 @ 09:05
    Nora
    0

    Hi Jeavon, I've got a similar question - which may is stupid .. but I can't figure out how to get it to work. I normally use the slimsy package and create the crops with defined height and width in the code. There are no crops defined on the image, just using the focal point to position the center of all crops used. This works great with slimsy. But at some point I have the requirement to generate a normal Image-Url. With the standard methods described in the documentation I can't get the image Url with the correct crops generated using the focal point of the image. Here is my actual code where I helped myself generating a URL without using the focal point:

    @if(childPage.HasValue("images")){
    var imageList= childPage.images.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
    var imageCollection = Umbraco.Media(imageList);
    
    foreach (var myImageCrop in imageCollection)
    {
        var imageCropUrl = "http://www.mydomain.at"[email protected] + "?mode=crop&width=188&height=103&rnd=130794336420000000";
         <img src="@imageCropUrl" >
    
    }
    

    Do you have any advice? Thanks a lot. Nora

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 26, 2016 @ 09:16
    Jeavon Leopold
    0

    Hi Nora,

    I think you want something like this:

    @if (childPage.HasValue("images"))
    {
        string[] imageList = childPage.images.ToString().Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries);
        var imageCollection = Umbraco.TypedMedia(imageList);
    
        foreach (var myImage in imageCollection)
        {
            var imageCropUrl = myImage.GetCropUrl(188, 103);
            <img src="@imageCropUrl">
    
        }
    }
    

    I don't think this is related to this existing thread at all though...?

    Jeavon

  • Marcin Zajkowski 112 posts 585 karma points MVP 6x c-trib
    Sep 26, 2016 @ 09:19
    Marcin Zajkowski
    0

    Hi Nora,

    why not to go simple way and use TypedMedia and extension method GetCropUrl()? Try below code (untested, but should work :)).

    @if(childPage.HasValue("images")){
    var imageList= childPage.images.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
    var imageCollection = Umbraco.TypedMedia(imageList);
    
    foreach (var myImageCrop in imageCollection)
    {
        var imageCropUrl = myImageCrop.GetCropUrl(width: 188, height: 103);    
    }
    
  • Nora 28 posts 97 karma points
    Sep 26, 2016 @ 09:57
    Nora
    0

    Thanks a lot to both of you! Would have been so easy ... I just didn't thought of changing to TypedMedia. Thank you :)

Please Sign in or register to post replies

Write your reply to:

Draft