You are here

function imageapi_image_open in ImageAPI 5

Same name and namespace in other branches
  1. 6 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 365
An ImageAPI supporting mulitple image toolkits. Image toolkits are implemented as modules. Images are objects, but have no methods

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;
}