Copied to clipboard

Flag this post as spam?

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


  • Thomas Won Nyheim 33 posts 145 karma points
    Oct 24, 2019 @ 11:32
    Thomas Won Nyheim
    0

    Image Cropper, fetching width / height or getting a double sized image

    Is there any way to fetch the width and height of an image cropper alias?

    Or just fetch a 2x size of the cropped image?

    I tried making another alias for the smaller image, but they will operate separately and will not maintain the same crop, unless the editor changes both.

  • Ben Abbott 19 posts 124 karma points
    Oct 24, 2019 @ 16:59
    Ben Abbott
    0

    You could try something like this...

    Int32 width;
    Int32 height;
    
    Int32 imgId = content.GetPropertyValue<Int32>("YourImagePickerAlias")
    
    IPublishedContent mediaImage = umbracoHelper.Media(imgId);
    
    ImageCropDataSet cropDS = mediaImage.GetPropertyValue<ImageCropDataSet>("umbracoFile");
    
    if (cropDS != null)
    {
         ImageCropData crop = cropDS.Crops.FirstOrDefault(x => x.Alias.Equals("YourCropNameHere", StringComparison.InvariantCultureIgnoreCase));
    
         if (crop != null)
         {
             width = crop.Width;
             height = crop.Height;
         }
         else
         {
             width = mediaImage.GetPropertyValue<Int32>("umbracoWidth");
             height = mediaImage.GetPropertyValue<Int32>("umbracoHeight");
          }
      }
    
  • Thomas Won Nyheim 33 posts 145 karma points
    Oct 31, 2019 @ 09:56
    Thomas Won Nyheim
    0

    Thank you, for your reply. But this requires to do a call to a image file to fetch the width and height of it. I was hoping there would be another way.

Please Sign in or register to post replies

Write your reply to:

Draft