[Jaws-commits] r12405 - in trunk/jaws/html/include/Jaws: . Image

afz at jaws-project.com afz at jaws-project.com
Sat Jan 14 12:29:45 UTC 2012


Author: afz
Date: 2012-01-14 12:29:45 +0000 (Sat, 14 Jan 2012)
New Revision: 12405

Modified:
   trunk/jaws/html/include/Jaws/Image.php
   trunk/jaws/html/include/Jaws/Image/GD.php
   trunk/jaws/html/include/Jaws/Image/Imagick.php
Log:
Added mirror(), flip(), gamma() and grayscale() methods to Jaws_Image for GD/Imagick drivers

Modified: trunk/jaws/html/include/Jaws/Image/GD.php
===================================================================
--- trunk/jaws/html/include/Jaws/Image/GD.php	2012-01-14 12:26:58 UTC (rev 12404)
+++ trunk/jaws/html/include/Jaws/Image/GD.php	2012-01-14 12:29:45 UTC (rev 12405)
@@ -250,6 +250,83 @@
     }
 
     /**
+     * Adjusts the image gamma
+     *
+     * @param float $gamma
+     *
+     * @return mixed True or a Jaws_Error on error
+     * @access public
+     **/
+    function gamma($gamma = 1.0)
+    {
+        $res = imagegammacorrect($this->_hImage, 1.0, $gamma);
+        if (false === $res) {
+            return Jaws_Error::raiseError('Failed transformation: gamma().',
+                                          'Jaws_Image_GD',
+                                          JAWS_ERROR_ERROR);
+        }
+
+        return true;
+    }
+
+    /**
+     * Horizontal mirroring
+     *
+     * @return mixed True or Jaws_Error on error
+     * @access public
+     **/
+    function mirror()
+    {
+        $new_img = $this->_createImage();
+        for ($x = 0; $x < $this->_img_w; ++$x) {
+            imagecopy($new_img, $this->_hImage, $x, 0, $this->_img_w - $x - 1, 0, 1, $this->_img_h);
+        }
+
+        imagedestroy($this->_hImage);
+        $this->_hImage = $new_img;
+        return true;
+    }
+
+    /**
+     * Vertical mirroring
+     *
+     * @return mixed True or Jaws_Error on error
+     * @access public
+     **/
+    function flip()
+    {
+        $new_img = $this->_createImage();
+        for ($y = 0; $y < $this->_img_h; ++$y) {
+            imagecopy($new_img, $this->_hImage, 0, $y, 0, $this->_img_h - $y - 1, $this->_img_w, 1);
+        }
+
+        imagedestroy($this->_hImage);
+        $this->_hImage = $new_img;
+        return true;
+    }
+
+    /**
+     * Converts an image into grayscale colors
+     *
+     * @return mixed True or Jaws_Error on error
+     **/
+    function grayscale()
+    {
+        $res = imagecopymergegray($this->_hImage,
+                                  $this->_hImage,
+                                  0, 0, 0, 0,
+                                  $this->_img_w, $this->_img_h,
+                                  0);
+        if (false === $res) {
+            return Jaws_Error::raiseError('Failed transformation: grayscale().',
+                                          'Jaws_Image_GD',
+                                          JAWS_ERROR_ERROR);
+        }
+
+        return true;
+    }
+
+    /**
      * Saves the image to a file
      *
      * @param string $filename the name of the file to write to

Modified: trunk/jaws/html/include/Jaws/Image/Imagick.php
===================================================================
--- trunk/jaws/html/include/Jaws/Image/Imagick.php	2012-01-14 12:26:58 UTC (rev 12404)
+++ trunk/jaws/html/include/Jaws/Image/Imagick.php	2012-01-14 12:29:45 UTC (rev 12405)
@@ -176,6 +176,83 @@
     }
 
     /**
+     * Adjusts the image gamma
+     *
+     * @param float $gamma
+     *
+     * @return mixed True or a Jaws_Error on error
+     * @access public
+     **/
+    function gamma($gamma = 1.0)
+    {
+        try {
+            $this->_hImage->gammaImage($gamma);
+        } catch (ImagickException $error) {
+            return Jaws_Error::raiseError('Failed transformation: gamma().',
+                                          'Jaws_Image_Imagick',
+                                          JAWS_ERROR_ERROR);
+        }
+
+        return true;
+    }
+
+    /**
+     * Horizontal mirroring
+     *
+     * @return mixed True or Jaws_Error on error
+     * @access public
+     **/
+    function mirror()
+    {
+        try {
+            $this->_hImage->flopImage();
+        } catch (ImagickException $error) {
+            return Jaws_Error::raiseError('Could not mirror the image.',
+                                          'Jaws_Image_Imagick',
+                                          JAWS_ERROR_ERROR);
+        }
+
+        return true;
+    }
+
+    /**
+     * Vertical mirroring
+     *
+     * @return mixed True or Jaws_Error on error
+     * @access public
+     **/
+    function flip()
+    {
+        try {
+            $this->_hImage->flipImage();
+        } catch (ImagickException $error) {
+            return Jaws_Error::raiseError('Could not flip the image.',
+                                          'Jaws_Image_Imagick',
+                                          JAWS_ERROR_ERROR);
+        }
+
+        return true;
+    }
+
+    /**
+     * Converts an image into grayscale colors
+     *
+     * @return mixed True or Jaws_Error on error
+     **/
+    function grayscale()
+    {
+        try {
+            $this->_hImage->setImageType(Imagick::IMGTYPE_GRAYSCALE);
+        } catch (ImagickException $error) {
+            return Jaws_Error::raiseError('Failed transformation: grayscale().',
+                                          'Jaws_Image_Imagick',
+                                          JAWS_ERROR_ERROR);
+        }
+
+        return true;
+    }
+
+    /**
      * Saves the image to a file
      *
      * @param string $filename the name of the file to write to

Modified: trunk/jaws/html/include/Jaws/Image.php
===================================================================
--- trunk/jaws/html/include/Jaws/Image.php	2012-01-14 12:26:58 UTC (rev 12404)
+++ trunk/jaws/html/include/Jaws/Image.php	2012-01-14 12:29:45 UTC (rev 12405)
@@ -91,7 +91,7 @@
      *
      * @access  public
      */
-    function &factory()
+    function &factory($imgDriver = '')
     {
         //extension_loaded
         $extensions = array(
@@ -99,15 +99,16 @@
             'imagick' => 'Imagick',
         );
 
-        $imgDriver = '';
-        foreach ($extensions as $ext => $ext_driver) {
-            if (extension_loaded($ext)) {
-                $imgDriver = $ext_driver;
-                break;
+        if (empty($imgDriver)) {
+            foreach ($extensions as $ext => $ext_driver) {
+                if (extension_loaded($ext)) {
+                    $imgDriver = $ext_driver;
+                    break;
+                }
             }
         }
 
-        if (empty($imgDriver)) {
+        if (empty($imgDriver) || !in_array($imgDriver, $extensions)) {
             return Jaws_Error::raiseError('No image library specified and none can be found.',
                                           'Jaws_Image',
                                           JAWS_ERROR_ERROR);
@@ -442,6 +443,59 @@
     }
 
     /**
+     * Adjusts the image gamma
+     *
+     * @param float $gamma
+     *
+     * @return mixed True or a Jaws_Error on error
+     * @access public
+     **/
+    function gamma($gamma = 1.0)
+    {
+        return Jaws_Error::raiseError('gamma() method not supported by driver.',
+                                      'Jaws_Image',
+                                      JAWS_ERROR_ERROR);
+    }
+
+    /**
+     * Horizontal mirroring
+     *
+     * @return mixed True or Jaws_Error on error
+     * @access public
+     **/
+    function mirror()
+    {
+        return Jaws_Error::raiseError('mirror() method not supported by driver.',
+                                      'Jaws_Image',
+                                      JAWS_ERROR_ERROR);
+    }
+
+    /**
+     * Vertical mirroring
+     *
+     * @return mixed True or Jaws_Error on error
+     * @access public
+     **/
+    function flip()
+    {
+        return Jaws_Error::raiseError('flip() method not supported by driver.',
+                                      'Jaws_Image',
+                                      JAWS_ERROR_ERROR);
+    }
+
+    /**
+     * Converts an image into grayscale colors
+     *
+     * @return mixed True or Jaws_Error on error
+     **/
+    function grayscale()
+    {
+        return Jaws_Error::raiseError('grayscale() method not supported by driver.',
+                                      'Jaws_Image',
+                                      JAWS_ERROR_ERROR);
+    }
+
+    /**
      * Saves image to file
      *
      * @param string $filename Filename to save image to



More information about the Jaws-commits mailing list