You are here

function image_styles in Drupal 7

Gets an array of all styles and their settings.

Return value

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

See also

image_style_load()

6 calls to image_styles()
ImageFileMoveTest::testNormal in modules/simpletest/tests/image.test
Tests moving a randomly generated image.
image_path_flush in modules/image/image.module
Clears 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
Loads a style by style name or ID.
image_style_name_validate in modules/image/image.admin.inc
Element validate function to ensure unique, URL safe style names.

... See full list

8 string references to 'image_styles'
ImageAdminStylesUnitTest::testDefaultStyle in modules/image/image.test
Test to override, edit, then revert a style.
ImageAdminStylesUnitTest::testStyle in modules/image/image.test
General test to add a style, add/remove/edit effects to it, then delete it.
ImageAdminUiTestCase::testEditEffectHelpText in modules/image/image.test
Test if the help text is available on the edit effect form.
image_schema in modules/image/image.install
Implements hook_schema().
image_style_flush in modules/image/image.module
Flushes cached media for a style.

... See full list

File

modules/image/image.module, line 565
Exposes global functionality for creating image styles.

Code

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['label'] = empty($style['label']) ? $style_name : $style['label'];
          $style['module'] = $module;
          $style['storage'] = IMAGE_STORAGE_DEFAULT;
          foreach ($style['effects'] as $key => $effect) {
            $definition = image_effect_definition_load($effect['name']);
            $effect = array_merge($definition, $effect);
            $style['effects'][$key] = $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;
}