1 image.gd.inc image_gd_resize(stdClass $image, $width, $height, $background = NULL)

Scale an image to the specified size using GD.


$image: An image object. The $image->resource, $image->info['width'], and $image->info['height'] values will be modified by this call.

$width: The new width of the resized image, in pixels.

$height: The new height of the resized image, in pixels.

$background: An hexadecimal integer specifying the background color to use for the uncovered area of the image after manipulation. E.g. 0x000000 for black, 0xff00ff for magenta, and 0xffffff for white. For images that support transparency, this will default to transparent. Otherwise it will default to white.

Return value

TRUE or FALSE, based on success.:

See also


Related topics


core/modules/system/image.gd.inc, line 72
GD2 toolkit for image manipulation within Backdrop.


function image_gd_resize(stdClass $image, $width, $height, $background = NULL) {
  $res = image_gd_create_tmp($image, $width, $height);

  if (!imagecopyresampled($res, $image->resource, 0, 0, 0, 0, $width, $height, $image->info['width'], $image->info['height'])) {
    return FALSE;

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