5

I used drush image-flush to delete all generated image style images on my site.

I know that image style images are automatically regenerated when you try to view them in a browser, but is there a way to "prime the cache" and automatically regenerate all image styles for all images after they have been deleted?

  • 1
    sounds like a unique use case, you plan on image-flushing all the time? – No Sssweat Nov 8 '15 at 7:11
  • 2
    No, this is not an operation I do frequently. But there are 20,000+ images, so it really slows things down for users while they are being regenerated. – Patrick Kenny Nov 8 '15 at 8:54
4

There is a module that could help with this task, it offers a couple of extra features also that can be useful.

Image Cache Info

Imageinfo Cache will generate image styles right after an image is uploaded and also on entity save. This will help with front end performance as the needed image style will already have been generated; thus the end user doesn't have to wait for the image to be generated. This can also mitigate some issues with image style generation if your CDN is configured incorrectly as the images will be generated without the request going through the CDN.

Comes with a drush command called image-generate. It will generate images for a given field and style.

There is also a beta version of a rules module (kind of older):

  • 1
    Image Cache Info worked for me. A few notes: I couldn't use the module itself because it replaces ImageMagick, which I needed for pic manipulation. Also, I had to disable ImageAPI Optimize module to run the drush command, then re-enable ImageAPI Optimize after the command was complete. – Patrick Kenny Nov 10 '15 at 11:44
5

I usually see people using wget or httrack for this - request every page in your site, and all of the images will be regenerated. Not very sophisticated, I know. As far as I know, though, there is no Drush command to do this.

  • 2
    Sounds like a good idea. Do you have any references on how to request every page in the site with the tools you mention? Thanks. – Mario Awad Nov 11 '15 at 11:23
2

If you want to generate image style programmatically for specific image using your custom code, here is the way:

image_style_create_derivative(image_style_load('medium'), $fileData->uri, image_style_path('medium', $fileData->uri));

In case that you are building your custom API and want to generate the image to prepare it for the next request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.