diff options
author | Mario Vavti <mario@mariovavti.com> | 2017-11-20 14:27:20 +0100 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2017-11-20 14:27:20 +0100 |
commit | 0325efeb350f575f70f18e9f199ad273e5ba1d15 (patch) | |
tree | 742ffbc2b46a31547f114124546353d3b1102157 /include/photo/photo_driver.php | |
parent | 9ab33f1e134e6e7694a42b92fc9d73c2e6dcffd1 (diff) | |
parent | 250d947667b1500633d80b043ac3760be21446fc (diff) | |
download | volse-hubzilla-0325efeb350f575f70f18e9f199ad273e5ba1d15.tar.gz volse-hubzilla-0325efeb350f575f70f18e9f199ad273e5ba1d15.tar.bz2 volse-hubzilla-0325efeb350f575f70f18e9f199ad273e5ba1d15.zip |
Merge remote-tracking branch 'mike/master' into dev
Diffstat (limited to 'include/photo/photo_driver.php')
-rw-r--r-- | include/photo/photo_driver.php | 109 |
1 files changed, 62 insertions, 47 deletions
diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 21431e96f..f75ff2386 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -241,69 +241,84 @@ abstract class photo_driver { } + /** + * @brief reads exif data from filename + */ + public function exif($filename) { - public function orient($filename) { - /** - * This function is a bit unusual, because it is operating on a file, but you must - * first create an image from that file to initialise the type and check validity - * of the image. - */ - - if(! $this->is_valid()) + if((! function_exists('exif_read_data')) + || (! in_array($this->getType(), [ 'image/jpeg' , 'image/tiff'] ))) { return false; + } - if((! function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg')) - return false; - - $exif = @exif_read_data($filename,null,true); - - if($exif) { - $ort = $exif['IFD0']['Orientation']; - - switch($ort) - { - case 1: // nothing - break; + /* + * PHP 7.2 allows you to use a stream resource, which should reduce/avoid + * memory exhaustion on large images. + */ - case 2: // horizontal flip - $this->flip(); - break; + if(version_compare(PHP_VERSION,'7.2.0') >= 0) { + $f = @fopen($filename,'rb'); + } + else { + $f = $filename; + } - case 3: // 180 rotate left - $this->rotate(180); - break; + if($f) { + return @exif_read_data($f); + } - case 4: // vertical flip - $this->flip(false, true); - break; + return false; + } - case 5: // vertical flip + 90 rotate right - $this->flip(false, true); - $this->rotate(-90); - break; + /** + * @brief orients current image based on exif orientation information + */ - case 6: // 90 rotate right - $this->rotate(-90); - break; + public function orient($exif) { - case 7: // horizontal flip + 90 rotate right - $this->flip(); - $this->rotate(-90); - break; + if(! ($this->is_valid() && $exif)) { + return false; + } - case 8: // 90 rotate left - $this->rotate(90); - break; - } + $ort = $exif['IFD0']['Orientation']; - return $exif; + if(! $ort) { + return false; + } + switch($ort) { + case 1: // nothing + break; + case 2: // horizontal flip + $this->flip(); + break; + case 3: // 180 rotate left + $this->rotate(180); + break; + case 4: // vertical flip + $this->flip(false, true); + break; + case 5: // vertical flip + 90 rotate right + $this->flip(false, true); + $this->rotate(-90); + break; + case 6: // 90 rotate right + $this->rotate(-90); + break; + case 7: // horizontal flip + 90 rotate right + $this->flip(); + $this->rotate(-90); + break; + case 8: // 90 rotate left + $this->rotate(90); + break; + default: + break; } - - return false; + return true; } |