public function GDToolkit::resize

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

Overrides ImageToolkitInterface::resize

File

drupal/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php, line 53
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 resize($image, $width, $height) {
  $res = $this
    ->createTmp($image, $width, $height);
  if (!imagecopyresampled($res, $image->resource, 0, 0, 0, 0, $width, $height, $image->info['width'], $image->info['height'])) {
    return FALSE;
  }
  imagedestroy($image->resource);

  // Update image object.
  $image->resource = $res;
  $image->info['width'] = $width;
  $image->info['height'] = $height;
  return TRUE;
}