Copied to clipboard

Flag this post as spam?

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


  • Gordon Saxby 1444 posts 1855 karma points
    Dec 09, 2016 @ 10:41
    Gordon Saxby
    0

    Create Crops for existing images

    We have a website with a reasonably big media library. We have just added some defined crops to the Image Cropper datatype - however, none of the existing images have any of the defined crops until the image is saved again.

    We can't go through the entire media library to save every image, to create the crops - so is there a simpler way?

  • David Peck 687 posts 1863 karma points c-trib
    Dec 09, 2016 @ 15:56
    David Peck
    0

    Do you NEED to save each image? I would expect GetCropUrl() to work even if the crop hadn't been selected based on the focus (blue blob) position of the image. That will be dead centre by default.

    If it is as you say then you should be able to write some code using the ContentService that grabs all media and saves it back with the crop.

    This code grabs the crop data for an IPublishedContent(mediaChild).

    @using Newtonsoft.Json
    @using Umbraco.Web.Models
    var imageCrops = JsonConvert.DeserializeObject<ImageCropDataSet>(mediaChild.GetPropertyValue<string>("umbracoFile"));
    

    It shouldn't be too hard to convert this to IContent use, change ImageCrops and save it back to the IContent.

Please Sign in or register to post replies

Write your reply to:

Draft