You are here

function image_get_sizes in Image 6

Same name and namespace in other branches
  1. 5.2 image.module \image_get_sizes()
  2. 5 image.module \image_get_sizes()
  3. 7 image_legacy.module \image_get_sizes()

Helper function to return the defined sizes (or proper defaults).

Parameters

$size: An optional string to return only the image size with the specified key.

$aspect_ratio: Float value with the ratio of image height / width. If a size has only one dimension provided this will be used to compute the other.

Return value

An associative array with width, height, and label fields for the size. If a $size parameter was specified and it cannot be found FALSE will be returned.

26 calls to image_get_sizes()
ImageTestCase::setUp in tests/image.test
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
image_admin_settings in ./image.admin.inc
Menu callback; Form builder function for image settings.
image_admin_settings_submit in ./image.admin.inc
Form submit handler for image admin settings form.
image_attach_block in contrib/image_attach/image_attach.module
Implementation of hook_block().
image_attach_form_node_type_form_alter in contrib/image_attach/image_attach.module
Implementation of hook_form_FORM_ID_alter().

... See full list

File

./image.module, line 938

Code

function image_get_sizes($size = NULL, $aspect_ratio = NULL) {
  $defaults = array(
    IMAGE_ORIGINAL => array(
      'width' => '',
      'height' => '',
      'label' => t('Original'),
      'operation' => 'scale',
      'link' => IMAGE_LINK_SHOWN,
    ),
    IMAGE_THUMBNAIL => array(
      'width' => 100,
      'height' => 100,
      'label' => t('Thumbnail'),
      'operation' => 'scale',
      'link' => IMAGE_LINK_SHOWN,
    ),
    IMAGE_PREVIEW => array(
      'width' => 640,
      'height' => 640,
      'label' => t('Preview'),
      'operation' => 'scale',
      'link' => IMAGE_LINK_SHOWN,
    ),
  );
  $sizes = array();
  foreach (variable_get('image_sizes', $defaults) as $key => $val) {

    // Only return sizes with a label.
    if (!empty($val['label'])) {

      // For a size with only one dimension specified, compute the other
      // dimension based on an aspect ratio.
      if ($aspect_ratio && (empty($val['width']) || empty($val['height']))) {
        if (empty($val['height']) && !empty($val['width'])) {
          $val['height'] = (int) round($val['width'] * $aspect_ratio);
        }
        elseif (empty($val['width']) && !empty($val['height'])) {
          $val['width'] = (int) round($val['height'] / $aspect_ratio);
        }
      }
      $sizes[$key] = $val;
    }
  }

  // If they requested a specific size return only that.
  if (isset($size)) {

    // Only return an array if it's available.
    return isset($sizes[$size]) ? $sizes[$size] : FALSE;
  }
  return $sizes;
}