Merge branch 'master' into nefformat
authorAndreas Unterkircher <unki@netshadow.at>
Sat, 29 Mar 2008 08:43:02 +0000 (09:43 +0100)
committerAndreas Unterkircher <unki@netshadow.at>
Sat, 29 Mar 2008 08:43:02 +0000 (09:43 +0100)
phpfspot.class.php

index be752eedda5fbd7368de4f6d5a08535a2790c3b2..8260cc967ddc21234094f6e76588acb31d272013 100644 (file)
@@ -1298,110 +1298,134 @@ class PHPFSPOT {
             }
 
             $src_img = @imagecreatefromjpeg($orig_image);
+            $handler = "gd";
             break;
 
          case 'image/png':
 
             $src_img = @imagecreatefrompng($orig_image);
+            $handler = "gd";
             break;
 
-      }
+         case 'image/tiff':
+
+            $src_img = new Imagick($orig_image);
+            print_r($src_img->queryFormats());
+            
+            $handler = "imagick";
+            exit(1);
+            break;
 
-      if(!$src_img) {
-         print "Can't load image from ". $orig_image ."\n";
-         return false;
       }
 
-      /* grabs the height and width */
-      $cur_width = imagesx($src_img);
-      $cur_height = imagesy($src_img);
 
-      // If requested width is more then the actual image width,
-      // do not generate a thumbnail, instead safe the original
-      // as thumbnail but with lower quality. But if the image
-      // is to heigh too, then we still have to resize it.
-      if($width >= $cur_width && $cur_height < $this->cfg->thumb_height) {
-         $result = imagejpeg($src_img, $thumb_image, 75);
-         imagedestroy($src_img);
-         return true;
-      }
+      switch($handler) {
 
-      // If the image will be rotate because EXIF orientation said so
-      // 'virtually rotate' the image for further calculations
-      if($rotate == 90 || $rotate == 270) {
-         $tmp = $cur_width;
-         $cur_width = $cur_height;
-         $cur_height = $tmp;
-      }
+         case 'gd':
 
-      /* calculates aspect ratio */
-      $aspect_ratio = $cur_height / $cur_width;
+            if(!isset($src_img) || empty($src_img)) {
+               print "Can't load image from ". $orig_image ."\n";
+               return false;
+            }
 
-      /* sets new size */
-      if($aspect_ratio < 1) {
-         $new_w = $width;
-         $new_h = abs($new_w * $aspect_ratio);
-      } else {
-         /* 'virtually' rotate the image and calculate it's ratio */
-         $tmp_w = $cur_height;
-         $tmp_h = $cur_width;
-         /* now get the ratio from the 'rotated' image */
-         $tmp_ratio = $tmp_h/$tmp_w;
-         /* now calculate the new dimensions */
-         $tmp_w = $width;
-         $tmp_h = abs($tmp_w * $tmp_ratio);
-
-         // now that we know, how high they photo should be, if it
-         // gets rotated, use this high to scale the image
-         $new_h = $tmp_h;
-         $new_w = abs($new_h / $aspect_ratio);
-
-         // If the image will be rotate because EXIF orientation said so
-         // now 'virtually rotate' back the image for the image manipulation
-         if($rotate == 90 || $rotate == 270) {
-            $tmp = $new_w;
-            $new_w = $new_h;
-            $new_h = $tmp;
-         }
-      }
+            /* grabs the height and width */
+            $cur_width = imagesx($src_img);
+            $cur_height = imagesy($src_img);
+
+            // If requested width is more then the actual image width,
+            // do not generate a thumbnail, instead safe the original
+            // as thumbnail but with lower quality. But if the image
+            // is to heigh too, then we still have to resize it.
+            if($width >= $cur_width && $cur_height < $this->cfg->thumb_height) {
+               $result = imagejpeg($src_img, $thumb_image, 75);
+               imagedestroy($src_img);
+               return true;
+            }
 
-      /* creates new image of that size */
-      $dst_img = imagecreatetruecolor($new_w, $new_h);
+            // If the image will be rotate because EXIF orientation said so
+            // 'virtually rotate' the image for further calculations
+            if($rotate == 90 || $rotate == 270) {
+               $tmp = $cur_width;
+               $cur_width = $cur_height;
+               $cur_height = $tmp;
+            }
 
-      imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
+            /* calculates aspect ratio */
+            $aspect_ratio = $cur_height / $cur_width;
 
-      /* copies resized portion of original image into new image */
-      imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img));
+            /* sets new size */
+            if($aspect_ratio < 1) {
+               $new_w = $width;
+               $new_h = abs($new_w * $aspect_ratio);
+            } else {
+               /* 'virtually' rotate the image and calculate it's ratio */
+               $tmp_w = $cur_height;
+               $tmp_h = $cur_width;
+               /* now get the ratio from the 'rotated' image */
+               $tmp_ratio = $tmp_h/$tmp_w;
+               /* now calculate the new dimensions */
+               $tmp_w = $width;
+               $tmp_h = abs($tmp_w * $tmp_ratio);
+
+               // now that we know, how high they photo should be, if it
+               // gets rotated, use this high to scale the image
+               $new_h = $tmp_h;
+               $new_w = abs($new_h / $aspect_ratio);
+
+               // If the image will be rotate because EXIF orientation said so
+               // now 'virtually rotate' back the image for the image manipulation
+               if($rotate == 90 || $rotate == 270) {
+                  $tmp = $new_w;
+                  $new_w = $new_h;
+                  $new_h = $tmp;
+               }
+            }
 
-      /* needs the image to be flipped horizontal? */
-      if($flip_hori) {
-         $this->_debug("(FLIP)");
-         $dst_img = $this->flipImage($dst_img, 'hori');
-      }
-      /* needs the image to be flipped vertical? */
-      if($flip_vert) {
-         $this->_debug("(FLIP)");
-         $dst_img = $this->flipImage($dst_img, 'vert');
-      }
+            /* creates new image of that size */
+            $dst_img = imagecreatetruecolor($new_w, $new_h);
 
-      if($rotate) {
-         $this->_debug("(ROTATE)");
-         $dst_img = $this->rotateImage($dst_img, $rotate);
-      }
+            imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
 
-      /* write down new generated file */
-      $result = imagejpeg($dst_img, $thumb_image, 75);
+            /* copies resized portion of original image into new image */
+            imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img));
 
-      /* free your mind */
-      imagedestroy($dst_img);
-      imagedestroy($src_img);
+            /* needs the image to be flipped horizontal? */
+            if($flip_hori) {
+               $this->_debug("(FLIP)");
+               $dst_img = $this->flipImage($dst_img, 'hori');
+            }
+            /* needs the image to be flipped vertical? */
+            if($flip_vert) {
+               $this->_debug("(FLIP)");
+               $dst_img = $this->flipImage($dst_img, 'vert');
+            }
 
-      if($result === false) {
-         print "Can't write thumbnail ". $thumb_image ."\n";
-         return false;
-      }
+            if($rotate) {
+               $this->_debug("(ROTATE)");
+               $dst_img = $this->rotateImage($dst_img, $rotate);
+            }
 
-      return true;
+            /* write down new generated file */
+            $result = imagejpeg($dst_img, $thumb_image, 75);
+
+            /* free your mind */
+            imagedestroy($dst_img);
+            imagedestroy($src_img);
+
+            if($result === false) {
+               print "Can't write thumbnail ". $thumb_image ."\n";
+               return false;
+            }
+
+            return true;
+
+            break;
+
+         case 'imagick':
+
+            break;
+
+      }
 
    } // create_thumbnail()
 
@@ -1856,7 +1880,7 @@ class PHPFSPOT {
     */
    public function checkifImageSupported($mime)
    {
-      if(in_array($mime, Array("image/jpeg", "image/png")))
+      if(in_array($mime, Array("image/jpeg", "image/png", "image/tiff")))
          return true;
 
       return false;