Change record status: 
Project: 
Introduced in branch: 
8.x
Introduced in version: 
8.0-ALPHA4
Description: 

Image toolkits should declare what image formats it can handle, by implementing the new supportedTypes() static method. The method should return an array of image types. An image type is represented by a PHP IMAGETYPE_* constant (e.g. IMAGETYPE_JPEG, IMAGETYPE_PNG, etc). Example taken from GD Toolkit, shipped with Drupal 8:

<?php
public static function supportedTypes() {
  return array(
IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF);
}
?>

The image interface (\Drupal\Core\Image\ImageInterface) is declaring 2 new methods:

  1. getType(): This method is returning the image format in the same IMAGETYPE_* way.
  2. isSupported(): Is used to check if the image is supported by the active toolkit.

In Drupal 7 the image extension was used to test if we got a valid image or to test the image format. In Drupal 8 we use \Drupal\Core\Image\ImageInterface::isSupported() to test the image validity and \Drupal\Core\Image\ImageInterface::getType() to get or test the image type.

D7

<?php
if ($image->info['extension'] == 'gif') { }
?>

D8

<?php
if ($image->getType() == IMAGETYPE_GIF) { }
?>
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done