Copied to clipboard

Flag this post as spam?

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


  • Jason Espin 368 posts 1335 karma points
    Sep 06, 2014 @ 20:25
    Jason Espin
    0

    Apply crop size changes to media items automatically v7

    Hi all,

    I've run into a predicament with Umbraco v7.1.4 and I was wondering if anyone has any ideas of how to get around it. Basically my end user would like to modify an image crop and apply it to all images in their media directory. The problem is, they have 2000 images in their media folder. As far as I know, the recommendation at the moment when adding a new image crop or modifying one is to manually resave the image so that the crop is applied. I thought this would work programmatically using the mediaservice so I wrote the following function that can be called using a url with an appended querystring:

    private void RefreshCrops()
    {
        IEnumerable<IMedia> rootMedia = ms.GetRootMedia().Where(x => x.ContentType.Alias == "ImageFolder");
    
        IMedia umb_parentNode = rootMedia.ElementAt(0);
    
        IEnumerable<IMedia> umb_images = ms.GetDescendants(umb_parentNode.Id).Where(x => x.ContentType.Alias == "Image");
    
        umb_images.ForEach(x => ms.Save(x));
    
    }
    

    I have run this function but unfortunately it doesn't appear to work. The crops are used in a rotating gallery that is stored as a RTE macro in Umbraco. This gallery has a cache time of 10 seconds. Could this be the reason why I am not seeing the new image crops after running this method?

    Any help or alternative methods would be greatly appreciated.

    J

  • Daniel Bardi 927 posts 2562 karma points
    Dec 09, 2014 @ 03:50
    Daniel Bardi
    0

    No one has respond for awhile...

    Media crops are automatic in v7.. no crop files are created so adding a new crop shouldn't be an issue.

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Dec 09, 2014 @ 08:59
    Dave Woestenborghs
    100

    Jeavon has created a package for this. This hooks in to the save event to of the crop datatype and resaves all crops.

    https://github.com/Jeavon/Umbraco-Crop-Healer

Please Sign in or register to post replies

Write your reply to:

Draft