You are here

function image_get_derivative_sizes in Image 5

Same name and namespace in other branches
  1. 5.2 image.module \image_get_derivative_sizes()
  2. 6 image.module \image_get_derivative_sizes()

Determine which sizes of derivative images need to be built for this image.

Parameters

$image_path: String file path to the image.

Return value

Returns a subset of image_get_sizes()'s results depending on what derivative images are needed.

4 calls to image_get_derivative_sizes()
image_insert in ./image.module
Implementation of hook_insert
image_load in ./image.module
Implementation of hook_load
image_update in ./image.module
Implementation of hook_update
_image_build_derivatives in ./image.module
Generate image derivatives.

File

./image.module, line 874

Code

function image_get_derivative_sizes($image_path) {
  $sizes = array();

  // Can't do much if we can't read the image.
  if (!($image_info = image_get_info($image_path))) {
    return $sizes;
  }
  $all_sizes = image_get_sizes(NULL, $image_info['height'] / $image_info['width']);
  foreach ($all_sizes as $key => $size) {

    // We don't want to include the original.
    if ($key == IMAGE_ORIGINAL) {
      continue;
    }

    // If the original isn't bigger than the requested size then there's no
    // need to resize it.
    if ($image_info['width'] > $size['width'] || $image_info['height'] > $size['height']) {
      $sizes[$key] = $size;
    }
  }
  return $sizes;
}