public function GDToolkit::load

Implements \Drupal\system\Plugin\ImageToolkitInterface::load().

Overrides ImageToolkitInterface::load

File

drupal/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php, line 156
Contains \Drupal\system\Plugin\ImageToolkit\GDToolkit;.

Class

GDToolkit
Defines the GD2 toolkit for image manipulation within Drupal.

Namespace

Drupal\system\Plugin\ImageToolkit

Code

public function load($image) {
  $extension = str_replace('jpg', 'jpeg', $image->info['extension']);
  $function = 'imagecreatefrom' . $extension;
  if (function_exists($function) && ($image->resource = $function($image->source))) {
    if (!imageistruecolor($image->resource)) {

      // Convert indexed images to true color, so that filters work
      // correctly and don't result in unnecessary dither.
      $new_image = $this
        ->createTmp($image, $image->info['width'], $image->info['height']);
      imagecopy($new_image, $image->resource, 0, 0, 0, 0, $image->info['width'], $image->info['height']);
      imagedestroy($image->resource);
      $image->resource = $new_image;
    }
    return (bool) $image->resource;
  }
  return FALSE;
}