Search code examples
drupaldrupal-7

How to programmatically delete an image style in Drupal?


Need help trying to figure out how to programmatically delete an image style in Drupal 7.


Solution

  • $image_style = image_style_load('IMAGE_STYLE');
    image_style_delete($image_style);
    

    See https://api.drupal.org/api/drupal/modules!image!image.module/function/image_style_delete/7

    You may need to flush the image style cache before it'll let you delete it. You can do that with:

    image_style_flush($image_style);
    

    For more info, see:

    1. https://api.drupal.org/api/drupal/modules!image!image.module/function/image_style_flush/7
    2. http://www.benmarshall.me/programmatically-create-delete-image-styles-drupal/