getgrav / grav-plugin-admin

Grav Admin Plugin
http://getgrav.org
MIT License
355 stars 227 forks source link

Generate image alternatives when uploading #806

Open fredrikekelund opened 8 years ago

fredrikekelund commented 8 years ago

I've been using Grav's image editing functionality quite heavily and reported several issues around it over the last few months. It's a great feature, but performing image editing operations at request time can be rather costly, especially when using ImageMedium#derivatives, which generates image variations for the srcset HTML attribute. But Grav also supports pregenerated responsive image variations, through a file naming convention.

I think it would be logical to add a feature to the admin panel that would generate a configurable set of image variations at upload time. This would ensure that the first request to the page wouldn't be slow, and it would be a transparent feature that mimics how a lot of other CMS's work.

The problem I'm trying to address here is that slow initial request, and I thought of suggesting a solution where the admin panel would also render the page after saving it, triggering any heavy image processing before the first visitor would arrive to the page. These two features could maybe complement one another, but the former seemed like the most logical one to begin with.

rhukster commented 8 years ago

I do think it would be valuable to have some logic in the retina/derivatives image logic so that if an appropriate file is already uploaded Grav will use that rather than creating the various individual images.

I hope to have some time to spend on this, but other things keep getting in the way.

fredrikekelund commented 8 years ago

I guess you probably already know this, but just to ensure that we're talking about the same thing (and given that you said that you weren't very familiar with the derivatives logic in the ImageMedium class) - there's already such logic! If multiple images have the same filename, apart from a modifier at the end (like @2x or @5x), then those images will be combined into a single ImageMedium. So generating those alternatives at upload time should really only involve the generation part. It could probably even be a pretty straightforward patch

rhukster commented 8 years ago

Yah that was user contributed code, and I am not super familiar with it :)