image.module

Same filename and directory in other branches
  1. 11.x core/modules/image/image.module
  2. 10 core/modules/image/image.module
  3. 9 core/modules/image/image.module
  4. 8.9.x core/modules/image/image.module
  5. 7.x modules/image/image.module

File

core/modules/image/image.module

View source
<?php


/**
 * @file
 */

use Drupal\image\Entity\ImageStyle;

/**
 * The name of the query parameter for image derivative tokens.
 */
define('IMAGE_DERIVATIVE_TOKEN', 'itok');

/**
 * Clears cached versions of a specific file in all styles.
 *
 * @param string $path
 *   The Drupal file path to the original image.
 */
function image_path_flush($path) : void {
  $styles = ImageStyle::loadMultiple();
  foreach ($styles as $style) {
    $style->flush($path);
  }
}

/**
 * Gets an array of image styles suitable for using as select list options.
 *
 * @param bool $include_empty
 *   If TRUE a '- None -' option will be inserted in the options array.
 *
 * @return string[]
 *   Array of image styles both key and value are set to style name.
 */
function image_style_options($include_empty = TRUE) : array {
  $styles = ImageStyle::loadMultiple();
  $options = [];
  if ($include_empty && !empty($styles)) {
    $options[''] = t('- None -');
  }
  foreach ($styles as $name => $style) {
    $options[$name] = $style->label();
  }
  if (empty($options)) {
    $options[''] = t('No defined styles');
  }
  return $options;
}

Functions

Title Deprecated Summary
image_path_flush Clears cached versions of a specific file in all styles.
image_style_options Gets an array of image styles suitable for using as select list options.

Constants

Title Deprecated Summary
IMAGE_DERIVATIVE_TOKEN The name of the query parameter for image derivative tokens.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.