62

I have an image style in Drupal 7. I attached several images to a nodes and display the images based on this style. I then changed the effects on this image style but the existing images are not being recreated with the new image style effects. They show with the old image style effects.

If I attach new images, they use the new effects. Deleting an existing image and re-uploading causes the image to use the old effects.

The manual (incorrectly I assume) states that just saving an image style causes a rebuild: http://drupal.org/documentation/modules/image

I have cleared the cached.

How do I force a rebuild?

3
  • 1
    Did you actually clicked on the Update style button when being at the Image Style page? I just did a few tests and verified that when you click it, all the generated files at the files directory get deleted.
    – Juampy NR
    Commented Jan 12, 2012 at 0:19
  • The manual is correct. Changing an image style, e.g. by adding, editing or deleting an effect, does flush the image style. It may be your browser (or another in between) cache or a rights problem when the derivatives are deleted.
    – fietserwin
    Commented Dec 10, 2014 at 17:36
  • I used custom drush command to regenerate images gist.github.com/typhonius/8599853
    – apostnikov
    Commented Jul 30, 2015 at 17:18

8 Answers 8

124

Clearing cache, won't flush image styles: http://drupal.org/node/997332

You could:

  • delete them manually
  • use image_style_flush
  • use the command line: rm -rf sites/default/files/styles
  • use drush: drush image-flush
2
  • 12
    drush image-flush style_name is a godsend. :-) Commented Apr 15, 2015 at 19:08
  • this may need a drush clear caches as well, specially if you are using CloudFlare on top Commented Dec 3, 2019 at 18:11
15

To flush Image Style Names in Drupal 7 through the UI, try this contrib module:

http://drupal.org/project/imagestyleflush

It gives you a flush option for each Image Style Name. It also has an option to flush all the Image Style Names at once.

Once the module is enabled, in the admin UI go here to flush a particular image style:

admin/config/media/image-styles
9

This is a bug with image styles. If you are editing an image style and edit an effect that is already present, the images will not be flushed on update. However, if you delete that effect (I'm not talking about deleting the image style - delete the effect within the particular image style) and create a new one, the images will be flushed on update.

2
  • function image_effect_save() does call image_style_flush(), so this is not a bug.
    – fietserwin
    Commented Dec 10, 2014 at 17:37
  • 1
    Just because something's getting called doesn't mean that it's not a bug. Functionality is not present when it should be. That's the definition of a bug...
    – Kirkland
    Commented Jun 19, 2015 at 15:11
3

There is another, easier way. It's more a replacement than update, but it works fine. You can create a new image style based on the old one, but with new features (image actions) you wish. Then delete the old style; on the deletion confirmation page, you will find a drop list with available image styles, which you can use to replace the old one. This is a standard image style replacement function, I assume.

3

Just for information in Drupal 8 you have an "flush" option in the "Edit" dropdown in /admin/config/media/image-styles you can flush one by one.

2

Edit the style you want from admin/config/media/image-styles.

Click on 'update style' button on bottom, that will flush all the existing generated images in style folder and create new ones.

0
1

if u have a custom template and wanna force style for an image field :

 $style='full_content_width';
 $path=$node->my_img_field['und']['0']['uri'];
 $style_url = image_style_url($style, $path);
  print "<img src=".file_create_url($style_url)." >";
1

If you are using Drupal Console (and let's face it, why not?) then you can use:

drupal image:styles:flush image_style

Or

drupal isf image_style

Documentation: https://drupalconsole.com/docs/ca/commands/image-styles-flush

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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