function image_gd_load

Image toolkit callback: Creates a GD image resource from a file.

Parameters

$image: An image object. The $image->resource value will populated by this call.

Return value

TRUE or FALSE, based on success.

See also

hook_image_toolkits()

image_load()

Related topics

File

drupal/core/modules/system/image.gd.inc, line 247
GD2 toolkit for image manipulation within Drupal.

Code

function image_gd_load(stdClass $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 = image_gd_create_tmp($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;
}