You are here

function imageapi_image_open in ImageAPI 6

Same name and namespace in other branches
  1. 5 imageapi.module \imageapi_image_open()

Open an image file and return an image object.

Any changes to the file are not saved until imageapi_image_close() is called.

Parameters

$file: Path to an image file.

$toolkit: An optional, image toolkit name to override the default.

Return value

An image object or FALSE if there was a problem loading the file. The image object has the following properties:

  • 'source' - The original file path.
  • 'info' - The array of information returned by image_get_info()
  • 'toolkit' - The name of the image toolkit requested when the image was loaded.

Image tookits may add additional properties. The caller is advised not to monkey about with them.

File

./imageapi.module, line 371
An ImageAPI supporting additional image plugins as modules. Images are treated as objects, and images are not written per manipulation as Drupal's core image handling works.

Code

function imageapi_image_open($file, $toolkit = FALSE) {
  if (!$toolkit) {
    $toolkit = imageapi_default_toolkit();
  }
  if ($toolkit) {
    $image = new stdClass();
    $image->source = $file;
    $image->info = image_get_info($file);
    $image->toolkit = $toolkit;
    if (imageapi_toolkit_invoke('open', $image)) {
      return $image;
    }
  }
  return FALSE;
}