You are here

public function GDToolkit::extensionToImageType in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php \Drupal\system\Plugin\ImageToolkit\GDToolkit::extensionToImageType()

Returns the IMAGETYPE_xxx constant for the given extension.

This is the reverse of the image_type_to_extension() function.

Parameters

string $extension: The extension to get the IMAGETYPE_xxx constant for.

Return value

int The IMAGETYPE_xxx constant for the given extension, or IMAGETYPE_UNKNOWN for unsupported extensions.

See also

image_type_to_extension()

File

core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php, line 446

Class

GDToolkit
Defines the GD2 toolkit for image manipulation within Drupal.

Namespace

Drupal\system\Plugin\ImageToolkit

Code

public function extensionToImageType($extension) {
  if (in_array($extension, [
    'jpe',
    'jpg',
  ])) {
    $extension = 'jpeg';
  }
  foreach ($this
    ->supportedTypes() as $type) {
    if (image_type_to_extension($type, FALSE) === $extension) {
      return $type;
    }
  }
  return IMAGETYPE_UNKNOWN;
}