You are here

function imagepicker_scale_image in Image Picker 6.2

Same name and namespace in other branches
  1. 5.2 imagepicker.module \imagepicker_scale_image()
  2. 5 imagepicker.module \imagepicker_scale_image()
  3. 7 imagepicker.imagefuncs.inc \imagepicker_scale_image()

@file Image functions for imagepicker.

4 calls to imagepicker_scale_image()
imagepicker_copy_form_submit in ./imagepicker.functions.inc
Function to submit the copy form
imagepicker_import_batch in ./imagepicker.import.inc
imagepicker_postlet_do in contribs/imagepicker_postlet/imagepicker_postlet.module
Function to process the postlet applet callbacks
imagepicker_upload_form_submit in ./imagepicker.upload.inc
Submit form

File

./imagepicker.imagefuncs.inc, line 8
Image functions for imagepicker.

Code

function imagepicker_scale_image($source, $destination, $maxsize) {
  $info = image_get_info($source);
  if ($info) {
    $width = $maxsize >= $info['width'] ? $info['width'] : $maxsize;
    $height = $maxsize >= $info['height'] ? $info['height'] : $maxsize;
    $aspect = $info['height'] / $info['width'];
    if ($aspect < $height / $width) {
      $width = (int) min($width, $info['width']);
      $height = (int) round($width * $aspect);
    }
    else {
      $height = (int) min($height, $info['height']);
      $width = (int) round($height / $aspect);
    }
    return image_toolkit_invoke('resize', array(
      $source,
      $destination,
      $width,
      $height,
    ));
  }
  return FALSE;
}