[Jaws-commits] r12402 - in branches/0.8/html/include/Jaws: . Image

afz at jaws-project.com afz at jaws-project.com
Sat Jan 14 08:28:23 UTC 2012


Author: afz
Date: 2012-01-14 08:28:23 +0000 (Sat, 14 Jan 2012)
New Revision: 12402

Modified:
   branches/0.8/html/include/Jaws/Image.php
   branches/0.8/html/include/Jaws/Image/GD.php
   branches/0.8/html/include/Jaws/Image/Imagick.php
Log:
[Jaws_Image]: Improve some functionality

Modified: branches/0.8/html/include/Jaws/Image/GD.php
===================================================================
--- branches/0.8/html/include/Jaws/Image/GD.php	2012-01-13 22:14:18 UTC (rev 12401)
+++ branches/0.8/html/include/Jaws/Image/GD.php	2012-01-14 08:28:23 UTC (rev 12402)
@@ -148,12 +148,7 @@
      */
     function resize($new_w, $new_h, $options = null)
     {
-        $new_w = $this->_parse_size($new_w, $this->_img_w);
-        $new_h = $this->_parse_size($new_h, $this->_img_h);
-        if ($this->_img_w == $new_w && $this->_img_h == $new_h) {
-            return true;
-        }
-
+        $this->_parse_size_by_aspect_ratio($new_w, $new_h);
         $scaleMethod = $this->_getOption('scaleMethod', $options, 'smooth');
         $trueColor = ($scaleMethod == 'pixel') ? null : true;
         $new_img = $this->_createImage($new_w, $new_h, $trueColor);
@@ -239,10 +234,18 @@
 
         // Multiply by -1 to change the sign, so the image is rotated clockwise
         $this->_hImage = imagerotate($this->_hImage, $angle * -1, $mask);
+        if (false === $this->_hImage) {
+            return Jaws_Error::raiseError('Failed transformation: rotate().',
+                                          'Jaws_Image_GD',
+                                          JAWS_ERROR_ERROR);
+        }
+
         if (function_exists('imagesavealpha')) {
             imagesavealpha($this->_hImage, true); 
         }
 
+        $this->_img_w = imagesx($this->_hImage);
+        $this->_img_h = imagesy($this->_hImage);
         return true;
     }
 

Modified: branches/0.8/html/include/Jaws/Image/Imagick.php
===================================================================
--- branches/0.8/html/include/Jaws/Image/Imagick.php	2012-01-13 22:14:18 UTC (rev 12401)
+++ branches/0.8/html/include/Jaws/Image/Imagick.php	2012-01-14 08:28:23 UTC (rev 12402)
@@ -84,12 +84,7 @@
      */
     function resize($new_w, $new_h, $options = null)
     {
-        $new_w = $this->_parse_size($new_w, $this->_img_w);
-        $new_h = $this->_parse_size($new_h, $this->_img_h);
-        if ($this->_img_w == $new_w && $this->_img_h == $new_h) {
-            return true;
-        }
-
+        $this->_parse_size_by_aspect_ratio($new_w, $new_h);
         $scaleMethod = $this->_getOption('scaleMethod', $options, 'smooth');
         $blur = ($scaleMethod == 'pixel') ? 0 : 1;
         try {

Modified: branches/0.8/html/include/Jaws/Image.php
===================================================================
--- branches/0.8/html/include/Jaws/Image.php	2012-01-13 22:14:18 UTC (rev 12401)
+++ branches/0.8/html/include/Jaws/Image.php	2012-01-14 08:28:23 UTC (rev 12402)
@@ -152,18 +152,27 @@
     }
 
     /**
-     * Returns the MIME type of the image being manipulated
+     * Get new dimensions of image by fixed aspect ratio
      *
-     * @param string $type Image type to get MIME type for
-     *
-     * @return string The MIME type if available, or an empty string
-     * @access public
-     * @see PHP_Compat::image_type_to_mime_type()
-     * @link http://php.net/image_type_to_mime_type
+     * @param   mixed $new_w
+     * @param   mixed $new_h
+     * @return  bool
+     * @access  protected
      */
-    function getMimeType($type = null)
+    function _parse_size_by_aspect_ratio(&$new_w, &$new_h)
     {
-        return image_type_to_mime_type($this->_convert_image_type(($type) ? $type : $this->type));
+        $new_w = $this->_parse_size($new_w, $this->_img_w);
+        $new_h = $this->_parse_size($new_h, $this->_img_h);
+
+        $ratio = round($new_w / $this->_img_w);
+        if (($this->_img_h * $ratio) < $new_h) {
+            $new_h = $this->_img_h * $ratio;
+        } else {
+            $ratio = round($new_h / $this->_img_h);
+            $new_w = $this->_img_w * $ratio;
+        }
+
+        return true;
     }
 
     /**
@@ -372,7 +381,7 @@
      * @return Jaws_Error
      * @access public
      */
-    function getHandle()
+    function &getHandle()
     {
         return Jaws_Error::raiseError('getHandle() method not supported by driver.',
                                       'Jaws_Image',



More information about the Jaws-commits mailing list