4

I use Image Styles to automatically generate thumbnails (for teasers and views). I have a lot of images, so I end up with a lot of cached thumbnails in the /files/styles directory.

Is it safe to delete the contents of /files/styles without doing anything like clearing the cache in Drupal? My hope is that the thumbnails would be regenerated as needed without issue.

8

Yes, it's perfectly safe to delete the files/styles directory: Drupal will regenerate the images the next time someone attempts to access it.

The image module defines a menu router item, $directory_path . '/styles/%image_style', that maps to the callback image_style_deliver().

In turn, image_style_deliver() checks to see if the generated derivative image exists: if it does, it serves it. Otherwise, it calls image_style_create_derivative().

4

If you have lots of images, deleting everything inside files/styles is not recommended because regenerating this can have a large performance impact.

I usually run a cron to keep it clean:

0 1 * * * find /var/www/<project>/sites/default/files/styles -type f -atime +30 -delete

This only deletes files that were not accessed in the last 30 days.

  • 1
    Why do you need to keep it clean? The only real reason I can see might be to regain more space but in that case you should get more space on your hosting plan. Other than that, deleting images just means a slower request next time someone views one. – rooby Apr 21 '13 at 5:33
  • regaining diskspace is indeed the case. Getting more space on your hosting plan is not always free. So, doing a bit of housekeeping can delay the upgrade if you don't want to spend money right away. – tvlooy Apr 21 '13 at 18:50
1

It is safe to delete them. When you clear the image cache all it is doing it deleting the files in the cache directory. If a request for an image cache file is made and the said image cache file does not exist it will be generated as long as the source file still exists. Do not the delete the source files as this will cause errors.

If you can I would suggest installing Drush. It's a command line tool for a large number of Drupal management features. You can clear cache, download modules, backup your database etc...

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.