From 66510e20d36cb8da4f3012ef063de7bfce9b51aa Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 09 May 2012 07:52:28 -0400
Subject: [PATCH] Merge pull request #1 from Brianetta/de-svn

---
 program/include/rcube_image.php |   46 ++++++++++++++++++++++++++++------------------
 1 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/program/include/rcube_image.php b/program/include/rcube_image.php
index 9fe15fe..5ba6357 100644
--- a/program/include/rcube_image.php
+++ b/program/include/rcube_image.php
@@ -40,8 +40,7 @@
      */
     public function props()
     {
-        $rcmail = rcmail::get_instance();
-
+        // use GD extension
         if (function_exists('getimagesize') && ($imsize = @getimagesize($this->image_file))) {
             $width   = $imsize[0];
             $height  = $imsize[1];
@@ -49,12 +48,9 @@
             $type    = image_type_to_extension($imsize['2'], false);
         }
 
-        if (!$type && ($cmd = $rcmail->config->get('im_identify_path', false))) {
-            $id = rcmail::exec($cmd. ' 2>/dev/null {in}', array('in' => $this->image_file));
-            list(, $type, $size) = explode(' ', strtolower($id));
-            if ($size) {
-                list($width, $height) = explode('x', $size);
-            }
+        // use ImageMagick
+        if (!$type && ($data = $this->identify())) {
+            list($type, $width, $height) = $data;
         }
 
         if ($type) {
@@ -67,7 +63,6 @@
         }
     }
 
-
     /**
      * Resize image to a given size
      *
@@ -78,11 +73,10 @@
      */
     public function resize($size, $filename = null)
     {
-        $result   = false;
-        $rcmail   = rcmail::get_instance();
-        $convert  = $rcmail->config->get('im_convert_path', false);
-        $identify = $rcmail->config->get('im_identify_path', false);
-        $props    = $this->props();
+        $result  = false;
+        $rcube   = rcube::get_instance();
+        $convert = $rcube->config->get('im_convert_path', false);
+        $props   = $this->props();
 
         if (!$filename) {
             $filename = $this->image_file;
@@ -93,10 +87,10 @@
             $p['out']  = $filename;
             $p['in']   = $this->image_file;
             $p['size'] = $size.'x'.$size;
-            $p['type'] = $type = $props['type'];
+            $type      = $props['type'];
 
-            if (!$type) {
-                list(, $p['type']) = explode(' ', strtolower(rcmail::exec($identify . ' 2>/dev/null {in}', $p))); // for things like eps
+            if (!$type && ($data = $this->identify())) {
+                $type = $data[0];
             }
 
             $type = strtr($type, array("jpeg" => "jpg", "tiff" => "tif", "ps" => "eps", "ept" => "eps"));
@@ -104,7 +98,7 @@
             $p['-opts'] = array('-resize' => $size.'>');
 
             if (in_array($type, explode(',', $p['types']))) { // Valid type?
-                $result = rcmail::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace RGB -quality {quality} {-opts} {in} {type}:{out}', $p) === '';
+                $result = rcube::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace RGB -quality {quality} {-opts} {in} {type}:{out}', $p) === '';
             }
 
             if ($result) {
@@ -162,4 +156,20 @@
         return false;
     }
 
+    /**
+     * Identify command handler.
+     */
+    private function identify()
+    {
+        $rcube = rcube::get_instance();
+
+        if ($cmd = $rcube->config->get('im_identify_path')) {
+            $args = array('in' => $this->image_file, 'format' => "%m %[fx:w] %[fx:h]");
+            $id   = rcube::exec($cmd. ' 2>/dev/null -format {format} {in}', $args);
+
+            if ($id) {
+                return explode(' ', strtolower($id));
+            }
+        }
+    }
 }

--
Gitblit v1.9.1