diff options
author | zotlabs <mike@macgirvin.com> | 2017-09-30 15:17:47 -0700 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2017-09-30 15:17:47 -0700 |
commit | ea4d1b5101022f928336a20f193f8f73adb4d5a7 (patch) | |
tree | 0aca64b82f25c61f9cd241dc0dba2dc4e9c926e1 /include/photos.php | |
parent | bdecb61bfa170412c7db513e6b58a13d0b0930f3 (diff) | |
download | volse-hubzilla-ea4d1b5101022f928336a20f193f8f73adb4d5a7.tar.gz volse-hubzilla-ea4d1b5101022f928336a20f193f8f73adb4d5a7.tar.bz2 volse-hubzilla-ea4d1b5101022f928336a20f193f8f73adb4d5a7.zip |
use imagick converter for large photos
Diffstat (limited to 'include/photos.php')
-rw-r--r-- | include/photos.php | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/include/photos.php b/include/photos.php index c7c8fc0a4..5de68f162 100644 --- a/include/photos.php +++ b/include/photos.php @@ -66,7 +66,19 @@ function photo_upload($channel, $observer, $args) { $os_storage = 0; if($args['os_syspath'] && $args['getimagesize']) { - $imagedata = @file_get_contents($args['os_syspath']); + if($args['getimagesize'][0] > 1600 || $args['getimagesize'][1] > 1600) { + $imagick_path = get_config('system','imagick_convert_path'); + if($imagick_path && @file_exists($imagick_path)) { + $tmp_name = $args['os_syspath'] . '-001'; + $newsize = photo_calculate_1600_scale($args['getimagesize']); + exec($imagick_path . ' ' . $args['os_syspath'] . ' -resize ' . $newsize . '^ ' . $tmp_name); + $imagedata = @file_get_contents($tmp_name); + @unlink($tmp_name); + } + } + else { + $imagedata = @file_get_contents($args['os_syspath']); + } $filename = $args['filename']; $filesize = strlen($imagedata); // this is going to be deleted if it exists @@ -122,7 +134,6 @@ function photo_upload($channel, $observer, $args) { } logger('photo_upload: loading the contents of ' . $src , LOGGER_DEBUG); - $imagedata = @file_get_contents($src); } @@ -428,6 +439,70 @@ function photo_upload($channel, $observer, $args) { return $ret; } + +function photo_calculate_1600_scale($arr) { + + $max = 1600; + $width = $arr[0]; + $height = $arr[1]; + + $dest_width = $dest_height = 0; + + if((! $width)|| (! $height)) + return FALSE; + + if($width > $max && $height > $max) { + + // very tall image (greater than 16:9) + // constrain the width - let the height float. + + if((($height * 9) / 16) > $width) { + $dest_width = $max; + $dest_height = intval(( $height * $max ) / $width); + } + + // else constrain both dimensions + + elseif($width > $height) { + $dest_width = $max; + $dest_height = intval(( $height * $max ) / $width); + } + else { + $dest_width = intval(( $width * $max ) / $height); + $dest_height = $max; + } + } + else { + if( $width > $max ) { + $dest_width = $max; + $dest_height = intval(( $height * $max ) / $width); + } + else { + if( $height > $max ) { + // very tall image (greater than 16:9) + // but width is OK - don't do anything + + if((($height * 9) / 16) > $width) { + $dest_width = $width; + $dest_height = $height; + } + else { + $dest_width = intval(( $width * $max ) / $height); + $dest_height = $max; + } + } + else { + $dest_width = $width; + $dest_height = $height; + } + } + } + + return $dest_width . 'x' . $dest_height; + +} + + /** * @brief Returns a list with all photo albums observer is allowed to see. * |