function imagepicker_scale_image in Image Picker 7
Same name and namespace in other branches
- 5.2 imagepicker.module \imagepicker_scale_image()
- 5 imagepicker.module \imagepicker_scale_image()
- 6.2 imagepicker.imagefuncs.inc \imagepicker_scale_image()
Parameters
string $source:
string $destination:
integer $maxsize:
Return value
result code
3 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_upload_form_submit in ./imagepicker.upload.inc 
- Submit form
File
- ./imagepicker.imagefuncs.inc, line 17 
- @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL
Code
function imagepicker_scale_image($source, $destination, $maxsize) {
  $info = image_get_info($source);
  if ($info) {
    $image = image_load($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);
    }
    if (image_resize($image, $width, $height)) {
      return image_save($image, $destination);
    }
  }
  return FALSE;
}