You are here

function imagepicker_scale_image in Image Picker 5

Same name and namespace in other branches
  1. 5.2 imagepicker.module \imagepicker_scale_image()
  2. 6.2 imagepicker.imagefuncs.inc \imagepicker_scale_image()
  3. 7 imagepicker.imagefuncs.inc \imagepicker_scale_image()
1 call to imagepicker_scale_image()
imagepicker_upload_form_submit in ./imagepicker.module
Submit form

File

./imagepicker.module, line 434
Enables permitted roles to upload images for insertion into configured nodes.

Code

function imagepicker_scale_image($source, $destination, $maxsize) {
  $info = image_get_info($source);
  $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,
  ));
}