image_styles

Versions
7
image_styles()

Get an array of all styles and their settings.

see image_style_load()

Return value

An array of styles keyed by the image style ID (isid).

▾ 6 functions call image_styles()

image_field_formatter_info in modules/image/image.field.inc
Implement hook_field_formatter_info().
image_path_flush in modules/image/image.module
Clear cached versions of a specific file in all styles.
image_style_list in modules/image/image.admin.inc
Menu callback; Listing of all current image styles.
image_style_load in modules/image/image.module
Load a style by style name or ID. May be used as a loader for menu items.
image_style_name_validate in modules/image/image.admin.inc
Element validate function to ensure unique, URL safe style names.
image_style_options in modules/image/image.module
Get an array of image styles suitable for using as select list options.

Code

modules/image/image.module, line 382

<?php
function image_styles() {
  $styles = &drupal_static(__FUNCTION__);

  // Grab from cache or build the array.
  if (!isset($styles)) {
    if ($cache = cache_get('image_styles', 'cache')) {
      $styles = $cache->data;
    }
    else {
      $styles = array();

      // Select the module-defined styles.
      foreach (module_implements('image_default_styles') as $module) {
        $module_styles = module_invoke($module, 'image_default_styles');
        foreach ($module_styles as $style_name => $style) {
          $style['name'] = $style_name;
          $style['module'] = $module;
          $style['storage'] = IMAGE_STORAGE_DEFAULT;
          foreach ($style['effects'] as $ieid => $effect) {
            $definition = image_effect_definition_load($effect['name']);
            $effect = array_merge($definition, $effect);
            $effect['ieid'] = $ieid;
            $style['effects'][$ieid] = $effect;
          }
          $styles[$style_name] = $style;
        }
      }

      // Select all the user-defined styles.
      $user_styles = db_select('image_styles', NULL, array('fetch' => PDO::FETCH_ASSOC))
        ->fields('image_styles')
        ->orderBy('name')
        ->execute()
        ->fetchAllAssoc('name', PDO::FETCH_ASSOC);

      // Allow the user styles to override the module styles.
      foreach ($user_styles as $style_name => $style) {
        $style['module'] = NULL;
        $style['storage'] = IMAGE_STORAGE_NORMAL;
        $style['effects'] = image_style_effects($style);
        if (isset($styles[$style_name]['module'])) {
          $style['module'] = $styles[$style_name]['module'];
          $style['storage'] = IMAGE_STORAGE_OVERRIDE;
        }
        $styles[$style_name] = $style;
      }

      drupal_alter('image_styles', $styles);
      cache_set('image_styles', $styles);
    }
  }

  return $styles;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.