diff options
Diffstat (limited to 'include/photo')
-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; } |