source: branches/1.2/workflow/js/htmlarea/plugins/UploadImage/popups/ImageEditor/NetPBM.php @ 1349

Revision 1349, 8.0 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

  • Property svn:executable set to *
Line 
1<?php
2/***********************************************************************
3** Title.........:  NetPBM Driver
4** Version.......:  1.0
5** Author........:  Xiang Wei ZHUO <wei@zhuo.org>
6** Filename......:  NetPBM.php
7** Last changed..:  30 Aug 2003
8** Notes.........:  Orginal is from PEAR
9**/
10
11// +----------------------------------------------------------------------+
12// | PHP Version 4                                                        |
13// +----------------------------------------------------------------------+
14// | Copyright (c) 1997-2002 The PHP Group                                |
15// +----------------------------------------------------------------------+
16// | This source file is subject to version 2.02 of the PHP license,      |
17// | that is bundled with this package in the file LICENSE, and is        |
18// | available at through the world-wide-web at                           |
19// | http://www.php.net/license/2_02.txt.                                 |
20// | If you did not receive a copy of the PHP license and are unable to   |
21// | obtain it through the world-wide-web, please send a note to          |
22// | license@php.net so we can mail you a copy immediately.               |
23// +----------------------------------------------------------------------+
24// | Authors: Peter Bowyer <peter@mapledesign.co.uk>                      |
25// +----------------------------------------------------------------------+
26//
27//
28// Image Transformation interface using command line NetPBM
29
30require_once "Transform.php";
31
32Class Image_Transform_Driver_NetPBM extends Image_Transform
33{
34
35    /**
36     * associative array commands to be executed
37     * @var array
38     */
39    var $command = array();
40
41    /**
42     * Class Constructor
43     */
44    function Image_Transform_Driver_NetPBM()
45    {
46        $this->uid = md5($_SERVER['REMOTE_ADDR']);
47           
48        return true;
49    } // End function Image_NetPBM
50
51    /**
52     * Load image
53     *
54     * @param string filename
55     *
56     * @return mixed none or a PEAR error object on error
57     * @see PEAR::isError()
58     */
59    function load($image)
60    {
61        //echo $image;
62        $this->image = $image;
63        $this->_get_image_details($image);
64    } // End load
65
66    /**
67     * Resizes the image
68     *
69     * @return none
70     * @see PEAR::isError()
71     */
72    function _resize($new_x, $new_y)
73    {
74        // there's no technical reason why resize can't be called multiple
75        // times...it's just silly to do so
76
77        $this->command[] = IMAGE_TRANSFORM_LIB_PATH .
78                           "pnmscale -width $new_x -height $new_y";
79
80        $this->_set_new_x($new_x);
81        $this->_set_new_y($new_y);
82    } // End resize
83
84    /**
85     * Crop the image
86     *
87     * @param int $crop_x left column of the image
88     * @param int $crop_y top row of the image
89     * @param int $crop_width new cropped image width
90     * @param int $crop_height new cropped image height
91     */
92    function crop($crop_x, $crop_y, $crop_width, $crop_height)
93    {
94        $this->command[] = IMAGE_TRANSFORM_LIB_PATH .
95                            "pnmcut -left $crop_x -top $crop_y -width $crop_width -height $crop_height";
96    }
97
98    /**
99     * Rotates the image
100     *
101     * @param int $angle The angle to rotate the image through
102     */
103    function rotate($angle)
104    {
105        $angle = -1*floatval($angle);
106
107        if($angle > 90)
108        {   
109            $this->command[] = IMAGE_TRANSFORM_LIB_PATH . "pnmrotate -noantialias 90";
110            $this->rotate(-1*($angle-90));
111        }
112        else if ($angle < -90)
113        {
114            $this->command[] = IMAGE_TRANSFORM_LIB_PATH . "pnmrotate -noantialias -90";
115            $this->rotate(-1*($angle+90));
116        }
117        else
118            $this->command[] = IMAGE_TRANSFORM_LIB_PATH . "pnmrotate -noantialias $angle";
119    } // End rotate
120
121    /**
122     * Flip the image horizontally or vertically
123     *
124     * @param boolean $horizontal true if horizontal flip, vertical otherwise
125     */
126    function flip($horizontal)
127    {
128        if($horizontal)
129            $this->command[] = IMAGE_TRANSFORM_LIB_PATH . "pnmflip -lr";
130        else
131            $this->command[] = IMAGE_TRANSFORM_LIB_PATH . "pnmflip -tb";
132    }
133
134    /**
135     * Adjust the image gamma
136     *
137     * @param float $outputgamma
138     *
139     * @return none
140     */
141    function gamma($outputgamma = 1.0) {
142        $this->command[13] = IMAGE_TRANSFORM_LIB_PATH . "pnmgamma $outputgamma";
143    }
144
145    /**
146     * adds text to an image
147     *
148     * @param   array   options     Array contains options
149     *             array(
150     *                  'text'          // The string to draw
151     *                  'x'             // Horizontal position
152     *                  'y'             // Vertical Position
153     *                  'Color'         // Font color
154     *                  'font'          // Font to be used
155     *                  'size'          // Size of the fonts in pixel
156     *                  'resize_first'  // Tell if the image has to be resized
157     *                                  // before drawing the text
158     *                   )
159     *
160     * @return none
161     */
162    function addText($params)
163    {
164        $default_params = array('text' => 'This is Text',
165                                'x' => 10,
166                                'y' => 20,
167                                'color' => 'red',
168                                'font' => 'Arial.ttf',
169                                'size' => '12',
170                                'angle' => 0,
171                                'resize_first' => false);
172        // we ignore 'resize_first' since the more logical approach would be
173        // for the user to just call $this->_resize() _first_ ;)
174        extract(array_merge($default_params, $params));
175        $this->command[] = "ppmlabel -angle $angle -colour $color -size "
176                           ."$size -x $x -y ".$y+$size." -text \"$text\"";
177    } // End addText
178
179    function _postProcess($type, $quality, $save_type)
180    {
181        $type = is_null($type) || $type==''? $this->type : $type;
182        $save_type = is_null($save_type) || $save_type==''? $this->type : $save_type;
183        //echo "TYPE:". $this->type;
184        array_unshift($this->command, IMAGE_TRANSFORM_LIB_PATH
185                      . $type.'topnm '. $this->image);
186        $arg = '';
187        switch(strtolower($save_type)){
188            case 'gif':
189                $this->command[] = IMAGE_TRANSFORM_LIB_PATH . "ppmquant 256";
190                $this->command[] = IMAGE_TRANSFORM_LIB_PATH . "ppmto$save_type";
191                break;
192            case 'jpg':
193            case 'jpeg':
194                $arg = "--quality=$quality";
195                $this->command[] = IMAGE_TRANSFORM_LIB_PATH . "ppmto$save_type $arg";
196                break;
197            default:
198                $this->command[] = IMAGE_TRANSFORM_LIB_PATH . "pnmto$save_type $arg";
199                break;
200        } // switch
201        return implode('|', $this->command);
202    }
203
204    /**
205     * Save the image file
206     *
207     * @param $filename string the name of the file to write to
208     * @param string $type (jpeg,png...);
209     * @param int $quality 75
210     * @return none
211     */
212    function save($filename, $type=null, $quality = 85)
213    {
214        $cmd = $this->_postProcess('', $quality, $type) . ">$filename";
215           
216        //If you are using windows, you need the following line.
217                //$cmd = ereg_replace('/','\\',$cmd);
218        //echo $cmd."##";
219        system($cmd);
220        $this->command = array();
221    } // End save
222
223
224    /**
225     * Display image without saving and lose changes
226     *
227     * @param string $type (jpeg,png...);
228     * @param int $quality 75
229     * @return none
230     */
231    function display($type = null, $quality = 75)
232    {
233        header('Content-type: image/' . $type);
234        $cmd = $this->_postProcess($type, $quality);
235       
236        passthru($cmd);
237        $this->command = array();
238    }
239
240    /**
241     * Destroy image handle
242     *
243     * @return none
244     */
245    function free()
246    {
247        // there is no image handle here
248        return true;
249    }
250
251
252} // End class ImageIM
253?>
Note: See TracBrowser for help on using the repository browser.