aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/attach.php3
-rw-r--r--include/photo/photo_driver.php109
-rw-r--r--include/photos.php8
3 files changed, 72 insertions, 48 deletions
diff --git a/include/attach.php b/include/attach.php
index 0f07fe035..0f31ed012 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -951,6 +951,9 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
call_hooks('photo_upload_end', $ret);
}
+ \Zotlabs\Daemon\Master::Summon([ 'Thumbnail' , $hash ]);
+
+
if($dosync) {
$sync = attach_export_data($channel,$hash);
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;
}
diff --git a/include/photos.php b/include/photos.php
index 41a1d18cb..b1391f284 100644
--- a/include/photos.php
+++ b/include/photos.php
@@ -203,7 +203,13 @@ function photo_upload($channel, $observer, $args) {
return $ret;
}
- $exif = $ph->orient(($args['os_syspath']) ? $args['os_syspath'] : $src);
+ // obtain exif data from the source file if present
+
+ $exif = $ph->exif(($args['os_syspath']) ? $args['os_syspath'] : $src);
+
+ if($exif) {
+ $ph->orient($exif);
+ }
@unlink($src);