2014-05-21 69 views

回答

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

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

您可能需要刷新圖像樣式緩存之前它會告訴你刪除它。你可以做到這一點:

image_style_flush($image_style); 

欲瞭解更多信息,請參見:

  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/
+0

注* image_style_delete()中的代碼自動調用image_style_flush()。 @see https://api.drupal.org/api/drupal/modules!image!image.module/function/image_style_delete/7 – relipse

3
<?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); 
?> 

這不會對默認樣式的工作。建議不要刪除它們,因爲很多Drupal模塊都依賴於它。

更新:

如果你已經修改了默認樣式(縮略圖,中,大),你不能刪除它們。相反,你可以將它們恢復到原來的設置,就像這樣。

<?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); 
?> 
+0

感謝關於最好不要刪除它們的評論。有沒有辦法禁用默認的? – relipse

+0

另外,timofey,你說過「如果你修改了默認樣式」。我如何修改默認樣式?我想刪除它們,但由於無法完成,至少讓我更改每個標籤。謝謝 – relipse

相關問題