/var/www/hkosl.com/citysuper/uploader/lib/class_image.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php

/** This file is part of KCFinder project
  *
  *      @desc Abstract image driver class
  *   @package KCFinder
  *   @version 3.12
  *    @author Pavel Tzonkov <sunhater@sunhater.com>
  * @copyright 2010-2014 KCFinder Project
  *   @license http://opensource.org/licenses/GPL-3.0 GPLv3
  *   @license http://opensource.org/licenses/LGPL-3.0 LGPLv3
  *      @link http://kcfinder.sunhater.com
  */

namespace kcfinder;

abstract class 
image {
    const 
DEFAULT_JPEG_QUALITY 75;

/** Image resource or object
  * @var mixed */
    
protected $image;

/** Image width in pixels
  * @var integer */
    
protected $width;

/** Image height in pixels
  * @var integer */
    
protected $height;

/** Init error
  * @var bool */
    
protected $initError false;

/** Driver specific options
  * @var array */
    
protected $options = array();


/** Magic method which allows read-only access to all protected or private
  * class properties
  * @param string $property
  * @return mixed */

    
final public function __get($property) {
        return 
property_exists($this$property) ? $this->$property null;
    }


/** Constructor. Parameter $image should be:
  *   1. An instance of image driver class (copy instance).
  *   2. An image represented by the type of the $image property
  *      (resource or object).
  *   3. An array with two elements. First - width, second - height.
  *      Creates a blank image.
  *   4. A filename string. Get image form file.
  * Second paramaeter is used by pass some specific image driver options
  * @param mixed $image
  * @param array $options */

    
public function __construct($image, array $options=array()) {
        
$this->image $this->width $this->height null;
        
$imageDetails $this->buildImage($image);

        if (
$imageDetails !== false)
            list(
$this->image$this->width$this->height) = $imageDetails;
        else
            
$this->initError true;
        
$this->options $options;
    }


/** Factory pattern to load selected driver. $image and $options are passed
  * to the constructor of the image driver
  * @param string $driver
  * @param mixed $image
  * @return object */

    
final static function factory($driver$image, array $options=array()) {
        
$class __NAMESPACE__ "\\image_$driver";
        return new 
$class($image$options);
    }


/** Checks if the drivers in the array parameter could be used. Returns first
  * found one
  * @param array $drivers
  * @return string */

    
final static function getDriver(array $drivers=array('gd')) {
        foreach (
$drivers as $driver) {
            if (!
preg_match('/^[a-z0-9\_]+$/i'$driver))
                continue;
            
$class __NAMESPACE__ "\\image_$driver";
            if (
class_exists($class) && method_exists($class"available")) {
                eval(
"\$avail = $class::available();");
                if (
$avail) return $driver;
            }
        }
        return 
false;
    }


/** Returns an array. Element 0 - image resource. Element 1 - width. Element 2 - height.
  * Returns FALSE on failure.
  * @param mixed $image
  * @return array */

    
final protected function buildImage($image) {
        
$class get_class($this);

        if (
$image instanceof $class) {
            
$width $image->width;
            
$height $image->height;
            
$img $image->image;

        } elseif (
is_array($image)) {
            list(
$key$width) = each($image);
            list(
$key$height) = each($image);
            
$img $this->getBlankImage($width$height);

        } else
            
$img $this->getImage($image$width$height);

        return (
$img !== false)
            ? array(
$img$width$height)
            : 
false;
    }


/** Returns calculated proportional width from the given height
  * @param integer $resizedHeight
  * @return integer */

    
final public function getPropWidth($resizedHeight) {
        
$width round(($this->width $resizedHeight) / $this->height);
        if (!
$width$width 1;
        return 
$width;
    }


/** Returns calculated proportional height from the given width
  * @param integer $resizedWidth
  * @return integer */

    
final public function getPropHeight($resizedWidth) {
        
$height round(($this->height $resizedWidth) / $this->width);
        if (!
$height$height 1;
        return 
$height;
    }


/** Checks if PHP needs some extra extensions to use the image driver. This
  * static method should be implemented into driver classes like abstract
  * methods
  * @return bool */
    
static function available() { return false; }

/** Checks if file is an image. This static method should be implemented into
  * driver classes like abstract methods
  * @param string $file
  * @return bool */
    
static function checkImage($file) { return false; }

/** Resize image. Should return TRUE on success or FALSE on failure
  * @param integer $width
  * @param integer $height
  * @return bool */
    
abstract public function resize($width$height);

/** Resize image to fit in given resolution. Should returns TRUE on success
  * or FALSE on failure. If $background is set, the image size will be
  * $width x $height and the empty spaces (if any) will be filled with defined
  * color. Background color examples: "#5f5", "#ff67ca", array(255, 255, 255)
  * @param integer $width
  * @param integer $height
  * @param mixed $background
  * @return bool */
    
abstract public function resizeFit($width$height$background=false);

/** Resize and crop the image to fit in given resolution. Returns TRUE on
  * success or FALSE on failure
  * @param mixed $src
  * @param integer $offset
  * @return bool */
    
abstract public function resizeCrop($width$height$offset=false);


/** Rotate image
  * @param integer $angle
  * @param string $background
  * @return bool */
    
abstract public function rotate($angle$background="#000000");

    abstract public function 
flipHorizontal();

    abstract public function 
flipVertical();

/** Apply a PNG or GIF watermark to the image. $top and $left parameters sets
  * the offset of the watermark in pixels. Boolean and NULL values are possible
  * too. In default case (FALSE, FALSE) the watermark should be applyed to
  * the bottom right corner. NULL values means center aligning. If the
  * watermark is bigger than the image or it's partialy or fully outside the
  * image, it shoudn't be applied
  * @param string $file
  * @param mixed $top
  * @param mixed $left
  * @return bool */
    
abstract public function watermark($file$left=false$top=false);

/** Should output the image. Second parameter is used to pass some options like
  *   'file' - if is set, the output will be written to a file
  *   'quality' - compression quality
  * It's possible to use extra specific options required by image type ($type)
  * @param string $type
  * @param array $options
  * @return bool */
    
abstract public function output($type='jpeg', array $options=array());

/** This method should create a blank image with selected size. Should returns
  * resource or object related to the created image, which will be passed to
  * $image property
  * @param integer $width
  * @param integer $height
  * @return mixed */
    
abstract protected function getBlankImage($width$height);

/** This method should create an image from source image. Only first parameter
  * ($image) is input. Its type should be filename string or a type of the
  * $image property. See the constructor reference for details. The
  * parametters $width and $height are output only. Should returns resource or
  * object related to the created image, which will be passed to $image
  * property
  * @param mixed $image
  * @param integer $width
  * @param integer $height
  * @return mixed */
    
abstract protected function getImage($image, &$width, &$height);

}

?>