]> git.mxchange.org Git - friendica.git/blobdiff - include/Photo.php
The CSS code for shared messages is moved from "vier" to the global.css, so that...
[friendica.git] / include / Photo.php
index 4ab58369ec94203b8d1cbd749acdb3012cac87c2..45164333dd238d4fa937bccfa5c639839b432f77 100644 (file)
@@ -129,11 +129,12 @@ class Photo {
                     $this->image->setCompressionQuality($quality);
             }
 
-            $this->width  = $this->image->getImageWidth();
+                       // The 'width' and 'height' properties are only used by non-Imagick routines.
+                       $this->width  = $this->image->getImageWidth();
                        $this->height = $this->image->getImageHeight();
                        $this->valid  = true;
 
-            return true;
+                       return true;
                }
 
                $this->valid = false;
@@ -205,29 +206,8 @@ 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 {
-
-                               // FIXME - implement horizantal bias for scaling as in followin GD functions
-                               // to allow very tall images to be constrained only horizontally. 
-
-                $this->image->resizeImage($max, $max, imagick::FILTER_LANCZOS, 1, true);
-            } 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;
-        }
-
-        $width = $this->width;
-        $height = $this->height;
+        $width = $this->getWidth();
+        $height = $this->getHeight();
 
         $dest_width = $dest_height = 0;
 
@@ -283,6 +263,29 @@ 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());
+
+                       // These may not be necessary any more
+                       $this->width  = $this->image->getImageWidth();
+                       $this->height = $this->image->getImageHeight();
+
+                       return;
+        }
+
+
         $dest = imagecreatetruecolor( $dest_width, $dest_height );
         imagealphablending($dest, false);
         imagesavealpha($dest, true);
@@ -400,11 +403,9 @@ class Photo {
         if(!$this->is_valid())
             return FALSE;
 
-        if($this->is_imagick())
-            return $this->scaleImage($min);
 
-        $width = $this->width;
-        $height = $this->height;
+        $width = $this->getWidth();
+        $height = $this->getHeight();
 
         $dest_width = $dest_height = 0;
 
@@ -438,6 +439,8 @@ class Photo {
             }
         }
 
+        if($this->is_imagick())
+            return $this->scaleImage($dest_width,$dest_height);
 
         $dest = imagecreatetruecolor( $dest_width, $dest_height );
         imagealphablending($dest, false);
@@ -460,7 +463,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;
         }
@@ -482,19 +485,19 @@ class Photo {
         if(!$this->is_valid())
             return FALSE;
 
-        if($this->is_imagick()) {
-            $this->image->setFirstIterator();
-            do {
-                $this->image->cropImage($w, $h, $x, $y);
-                /**
-                 * We need to remove the canva,
-                 * or the image is not resized to the crop:
-                 * http://php.net/manual/en/imagick.cropimage.php#97232
-                 */
-                $this->image->setImagePage(0, 0, 0, 0);
-            } while ($this->image->nextImage());
-            return $this->scaleImage($max);
-        }
+               if($this->is_imagick()) {
+                       $this->image->setFirstIterator();
+                       do {
+                               $this->image->cropImage($w, $h, $x, $y);
+                               /**
+                                * We need to remove the canva,
+                                * or the image is not resized to the crop:
+                                * http://php.net/manual/en/imagick.cropimage.php#97232
+                                */
+                               $this->image->setImagePage(0, 0, 0, 0);
+                       } while ($this->image->nextImage());
+                       return $this->scaleImage($max);
+               }
 
         $dest = imagecreatetruecolor( $max, $max );
         imagealphablending($dest, false);
@@ -531,6 +534,9 @@ class Photo {
 
         ob_start();
 
+       // Enable interlacing
+       imageinterlace($this->image, true);
+
         switch($this->getType()){
             case "image/png":
                 $quality = get_config('system','png_quality');
@@ -581,6 +587,7 @@ class Photo {
                 `album` = '%s',
                 `height` = %d,
                 `width` = %d,
+                               `datasize` = %d,
                 `data` = '%s',
                 `scale` = %d,
                 `profile` = %d,
@@ -588,7 +595,7 @@ class Photo {
                 `allow_gid` = '%s',
                 `deny_cid` = '%s',
                 `deny_gid` = '%s'
-                where id = %d limit 1",
+                where id = %d",
 
                 intval($uid),
                 intval($cid),
@@ -601,6 +608,7 @@ class Photo {
                 dbesc($album),
                 intval($this->getHeight()),
                 intval($this->getWidth()),
+                               dbesc(strlen($this->imageString())),
                 dbesc($this->imageString()),
                 intval($scale),
                 intval($profile),
@@ -613,8 +621,8 @@ class Photo {
         }
         else {
             $r = q("INSERT INTO `photo`
-                ( `uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
-                VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s' )",
+                ( `uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `datasize`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
+                VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s' )",
                 intval($uid),
                 intval($cid),
                 dbesc($guid),
@@ -626,6 +634,7 @@ class Photo {
                 dbesc($album),
                 intval($this->getHeight()),
                 intval($this->getWidth()),
+                               dbesc(strlen($this->imageString())),
                 dbesc($this->imageString()),
                 intval($scale),
                 intval($profile),
@@ -662,7 +671,7 @@ function guess_image_type($filename, $fromcurl=false) {
     }
     if (is_null($type)){
         // Guessing from extension? Isn't that... dangerous?
-        if(class_exists('Imagick')) {
+        if(class_exists('Imagick') && file_exists($filename) && is_readable($filename)) {
             /**
              * Well, this not much better,
              * but at least it comes from the data inside the image,
@@ -670,6 +679,7 @@ function guess_image_type($filename, $fromcurl=false) {
              */
             $image = new Imagick($filename);
             $type = $image->getImageMimeType();
+            $image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
         } else {
             $ext = pathinfo($filename, PATHINFO_EXTENSION);
             $types = Photo::supportedTypes();