58

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?

  • 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 Jan 12 '12 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 Dec 10 '14 at 17:36
  • I used custom drush command to regenerate images gist.github.com/typhonius/8599853 – apostnikov Jul 30 '15 at 17:18
113

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
  • 9
    drush image-flush style_name is a godsend. :-) – Sean Robertson Apr 15 '15 at 19:08
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.

  • function image_effect_save() does call image_style_flush(), so this is not a bug. – fietserwin Dec 10 '14 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 Jun 19 '15 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

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.

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)." >";
0

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 image:styles:flush image_style

Documenation: https://docs.drupalconsole.com/en/commands/image-styles-flush.html

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.