Need help trying to figure out how to programmatically delete an image style in Drupal 7.
$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:
<?php
// Load the style.
$style = image_style_load('styleName');
// Flush images associated with the style.
image_style_flush($style);
// Delete the style.
image_style_delete($style);
?>
This will not work on the default styles. It is recommended to not remove them, since a number of Drupal modules depends on it.
Update:
If you've modified the default styles (Thumbnail, Medium, Large), you cannot delete them. Instead, you can just revert them back to their original settings, like this.
<?php
// Load the style.
$style = image_style_load('styleName');
// Flush images associated with the style.
image_style_flush($style);
// Revert the style.
image_default_style_revert($style);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With