【问题标题】:How to programmatically delete an image style in Drupal?如何以编程方式删除 Drupal 中的图像样式?
【发布时间】:2014-05-21 18:59:32
【问题描述】:

需要帮助尝试找出如何以编程方式删除 Drupal 7 中的图像样式。

【问题讨论】:

    标签: drupal drupal-7


    【解决方案1】:
    $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/

    【讨论】:

    【解决方案2】:
    <?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);
    ?>
    

    【讨论】:

    • 感谢您对最好不要删除它们的评论。有没有办法禁用默认的?
    • 另外,timofey,你说“如果你修改了默认样式”。我究竟如何修改默认样式?我想删除它们,但由于无法做到,至少让我更改每个标签上的标签。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 2015-04-07
    相关资源
    最近更新 更多