]> git.mxchange.org Git - friendica.git/blobdiff - include/Photo.php
Merge pull request #500 from fabrixxm/quattro-fontsoptions
[friendica.git] / include / Photo.php
index 8e4eb84bdba8cc6e0f6b1445edf12bd7b3946678..25a2b708038b2a935eea979dcb11e5ff3dbe82b7 100644 (file)
@@ -205,19 +205,6 @@ class Photo {
         if(!$this->is_valid())
             return FALSE;
 
-        if($this->is_imagick()) {
-            /**
-             * If it is not animated, there will be only one iteration here,
-             * so don't bother checking
-             */
-            // Don't forget to go back to the first frame
-            $this->image->setFirstIterator();
-            do {
-                $this->image->resizeImage($max, $max, imagick::FILTER_LANCZOS, 1, true);
-            } while ($this->image->nextImage());
-            return;
-        }
-
         $width = $this->width;
         $height = $this->height;
 
@@ -227,7 +214,18 @@ class Photo {
             return FALSE;
 
         if($width > $max && $height > $max) {
-            if($width > $height) {
+
+                       // 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);
             }
@@ -243,8 +241,18 @@ class Photo {
             }
             else {
                 if( $height > $max ) {
-                    $dest_width = intval(( $width * $max ) / $height);
-                    $dest_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;
@@ -254,6 +262,28 @@ class Photo {
         }
 
 
+        if($this->is_imagick()) {
+            /**
+             * If it is not animated, there will be only one iteration here,
+             * so don't bother checking
+             */
+            // Don't forget to go back to the first frame
+            $this->image->setFirstIterator();
+            do {
+
+                               // FIXME - implement horizantal bias for scaling as in followin GD functions
+                               // to allow very tall images to be constrained only horizontally. 
+
+                $this->image->scaleImage($dest_width, $dest_height);
+            } while ($this->image->nextImage());
+
+                       // FIXME - also we need to copy the new dimensions to $this->height, $this->width as other functions
+                       // may rely on it.
+
+            return;
+        }
+
+
         $dest = imagecreatetruecolor( $dest_width, $dest_height );
         imagealphablending($dest, false);
         imagesavealpha($dest, true);
@@ -371,8 +401,6 @@ class Photo {
         if(!$this->is_valid())
             return FALSE;
 
-        if($this->is_imagick())
-            return $this->scaleImage($min);
 
         $width = $this->width;
         $height = $this->height;
@@ -409,6 +437,8 @@ class Photo {
             }
         }
 
+        if($this->is_imagick())
+            return $this->scaleImage($dest_width,$dest_height);
 
         $dest = imagecreatetruecolor( $dest_width, $dest_height );
         imagealphablending($dest, false);
@@ -431,7 +461,7 @@ class Photo {
         if($this->is_imagick()) {
             $this->image->setFirstIterator();
             do {
-                $this->image->resizeImage($dim, $dim, imagick::FILTER_LANCZOS, 1, false);
+                $this->image->scaleImage($dim, $dim);
             } while ($this->image->nextImage());
             return;
         }
@@ -663,7 +693,7 @@ function import_profile_photo($photo,$uid,$cid) {
         intval($uid),
         intval($cid)
     );
-    if(count($r)) {
+    if(count($r) && strlen($r[0]['resource-id'])) {
         $hash = $r[0]['resource-id'];
     }
     else {