Passed
Push — master ( 8d8e58...047d50 )
by Michael
02:21
created

Image_Transform   F

Complexity

Total Complexity 153

Size/Duplication

Total Lines 1258
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1258
rs 0.6314
c 0
b 0
f 0
wmc 153

63 Methods

Rating   Name   Duplication   Size   Complexity  
B fit() 0 13 6
A _resize() 0 3 1
B intersects() 0 19 6
A addText() 0 3 1
A addBorder() 0 3 1
A greyscale() 0 3 1
A scaleByXY() 0 3 1
A colorarray2colorhex() 0 8 3
A colorhex2colorarray() 0 7 1
A keepSettingsOnSave() 0 3 1
A fitX() 0 3 2
A canvasResize() 0 3 1
A _get_default_text_params() 0 3 1
A isError() 0 7 2
A _set_new_y() 0 3 1
A getNewImageWidth() 0 7 2
A grayscale() 0 3 1
A _prepare_cmd() 0 8 3
A resize() 0 8 3
A setOptions() 0 3 1
A setOption() 0 3 1
A _send_display_headers() 0 7 1
C _get_image_details() 0 66 18
A _parse_size() 0 12 4
A free() 0 3 1
A scaleByFactor() 0 9 2
A getHandle() 0 3 1
A rotate() 0 3 1
D _convert_image_type() 0 40 18
A load() 0 3 1
A scaleMaxLength() 0 14 3
A addDropShadow() 0 3 1
A fitY() 0 3 2
A scaleByY() 0 8 2
A gamma() 0 3 1
A scaleByPercentage() 0 3 1
A getNewImageHeight() 0 7 2
A normalize() 0 3 1
A flip() 0 3 1
B _getColor() 0 18 5
A _set_new_x() 0 3 1
A _set_img_x() 0 3 1
A crop() 0 3 1
A _set_img_y() 0 3 1
A getMimeType() 0 3 2
A save() 0 3 1
A display() 0 3 1
A getImageType() 0 3 1
A scaleByLength() 0 3 1
A getImageSize() 0 8 1
A getWebSafeFormat() 0 9 3
A fitOnCanvas() 0 3 1
A scale() 0 8 4
A scaleByX() 0 8 2
A getImageHeight() 0 3 1
A getImageWidth() 0 3 1
A getTempFile() 0 8 2
A _getOption() 0 5 2
A getTempDir() 0 5 1
C factory() 0 62 14
A supportsType() 0 3 2
A _rotation_angle() 0 5 2
A mirror() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like Image_Transform often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Image_Transform, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 38 and the first side effect is on line 33.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/* vim: set expandtab tabstop=4 shiftwidth=4: */
4
5
/**
6
 * Simple and cross-library package to doing image transformations and
7
 * manipulations.
8
 *
9
 * PHP versions 4 and 5
10
 *
11
 * LICENSE: This source file is subject to version 3.0 of the PHP license
12
 * that is available through the world-wide-web at the following URI:
13
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
14
 * the PHP License and are unable to obtain it through the web, please
15
 * send a note to [email protected] so we can mail you a copy immediately.
16
 *
17
 * @category  Image
18
 * @package   Image_Transform
19
 * @author    Vincent Oostindie <[email protected]>
20
 * @author    Alan Knowles <[email protected]>
21
 * @author    Peter Bowyer <[email protected]>
22
 * @author    Philippe Jausions <[email protected]>
23
 * @copyright 2002-2007 The PHP Group
24
 * @license   http://www.php.net/license/3_0.txt  PHP License 3.0
25
 * @version   CVS: $Id: Transform.php 322659 2012-01-24 11:56:22Z clockwerx $
26
 * @link      http://pear.php.net/package/Image_Transform
27
 */
28
29
/**
30
 * Include for error handling
31
 */
32
//require_once 'PEAR.php';
33
require_once XOOPS_ROOT_PATH . '/modules/extgallery/class/pear/PEAR.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
34
35
/**
36
 * Error code for unsupported library, image format or methods
37
 */
38
define('IMAGE_TRANSFORM_ERROR_UNSUPPORTED', 1);
39
40
/**
41
 * Error code for failed transformation operations
42
 */
43
define('IMAGE_TRANSFORM_ERROR_FAILED', 2);
44
45
/**
46
 * Error code for failed i/o (Input/Output) operations
47
 */
48
define('IMAGE_TRANSFORM_ERROR_IO', 3);
49
50
/**
51
 * Error code for invalid arguments
52
 */
53
define('IMAGE_TRANSFORM_ERROR_ARGUMENT', 4);
54
55
/**
56
 * Error code for out-of-bound related errors
57
 */
58
define('IMAGE_TRANSFORM_ERROR_OUTOFBOUND', 5);
59
60
/**
61
 * Error code for inexsitant driver errors
62
 */
63
define('IMAGE_TRANSFORM_DRIVER_FILE_MISSING', 6);
64
65
/**
66
 * Base class with factory method for backend driver
67
 *
68
 * The main "Image_Transform" class is a container and base class which
69
 * provides a static method for creating an Image object as well as
70
 * some utility functions (maths) common to all parts of Image_Transform.
71
 *
72
 * @category  Image
73
 * @package   Image_Transform
74
 * @author    Alan Knowles <[email protected]>
75
 * @author    Peter Bowyer <[email protected]>
76
 * @author    Philippe Jausions <[email protected]>
77
 * @copyright 2002-2007 The PHP Group
78
 * @license   http://www.php.net/license/3_0.txt  PHP License 3.0
79
 * @version   Release: @package_version@
80
 * @link      http://pear.php.net/package/Image_Transform
81
 * @since     PHP 4.0
82
 */
83
class Image_Transform
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
84
{
85
    /**
86
     * Name of the image file
87
     * @var string
88
     */
89
    public $image = '';
90
91
    /**
92
     * Type of the image file (eg. jpg, gif png ...)
93
     * @var string
94
     */
95
    public $type = '';
96
97
    /**
98
     * Original image width in x direction
99
     * @var int
100
     */
101
    public $img_x = '';
102
103
    /**
104
     * Original image width in y direction
105
     * @var int
106
     */
107
    public $img_y = '';
108
109
    /**
110
     * New image width in x direction
111
     * @var int
112
     */
113
    public $new_x = '';
114
115
    /**
116
     * New image width in y direction
117
     * @var int
118
     */
119
    public $new_y = '';
120
121
    /**
122
     * Path to the library used
123
     * e.g. /usr/local/ImageMagick/bin/ or
124
     * /usr/local/netpbm/
125
     */
126
    public $lib_path = '';
127
128
    /**
129
     * Flag to warn if image has been resized more than once before displaying
130
     * or saving.
131
     */
132
    public $resized = false;
133
134
    /**
135
     * @var array General options
136
     * @access protected
137
     */
138
    public $_options = array(
139
        'quality'     => 75,
140
        'scaleMethod' => 'smooth',
141
        'canvasColor' => array(255, 255, 255),
142
        'pencilColor' => array(0, 0, 0),
143
        'textColor'   => array(0, 0, 0)
144
    );
145
146
    /**
147
     * Flag for whether settings should be discarded on saving/display of image
148
     * @var bool
149
     * @see Image_Transform::keepSettingsOnSave
150
     */
151
    public $keep_settings_on_save = false;
152
153
    /**
154
     * Supported image types
155
     * @var array
156
     * @access protected
157
     */
158
    public $_supported_image_types = array();
159
160
    /**
161
     * Initialization error tracking
162
     * @var object
163
     * @access private
164
     **/
165
    public $_error = null;
166
167
    /**
168
     * associative array that tracks existence of programs
169
     * (for drivers using shell interface and a tiny performance
170
     * improvement if the clearstatcache() is used)
171
     * @var array
172
     * @access protected
173
     */
174
    public $_programs = array();
175
176
    /**
177
     * Default parameters used in the addText methods.
178
     */
179
    public $default_text_params = array(
180
        'text'         => 'Default text',
181
        'x'            => 10,
182
        'y'            => 20,
183
        'color'        => 'red',
184
        'font'         => 'Arial.ttf',
185
        'size'         => 12,
186
        'angle'        => 0,
187
        'resize_first' => false
188
    );
189
190
    /**
191
     * Creates a new Image_Transform object
192
     *
193
     * @param string $driver name of driver class to initialize. If no driver
194
     *                       is specified the factory will attempt to use 'Imagick' first
195
     *                       then 'GD' second, then 'Imlib' last
196
     *
197
     * @return object an Image_Transform object, or PEAR_Error on error
198
     *
199
     * @see PEAR::isError()
200
     * @see Image_Transform::setOption()
201
     */
202
    public function &factory($driver = '')
203
    {
204
        if ('' == $driver) {
205
            $extensions = array(
206
                'imagick' => 'Imagick3',
207
                'gd'      => 'GD',
208
                'imlib'   => 'Imlib'
209
            );
210
            if (version_compare(PHP_VERSION, '5.0.0', '<')) {
211
                //Imagick2 driver for php < 5
212
                $extensions['imagick'] = 'Imagick2';
213
            }
214
215
            foreach ($extensions as $ext => $ext_driver) {
216
                if (PEAR::loadExtension($ext)) {
217
                    $driver = $ext_driver;
218
                    break;
219
                }
220
            }
221
            if (!$driver) {
222
                return PEAR::raiseError('No image library specified and none can be found.' . ' You must specify driver in factory() call.', IMAGE_TRANSFORM_ERROR_ARGUMENT);
0 ignored issues
show
Bug introduced by
The method raiseError() does not exist on PEAR. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

222
                return PEAR::/** @scrutinizer ignore-call */ raiseError('No image library specified and none can be found.' . ' You must specify driver in factory() call.', IMAGE_TRANSFORM_ERROR_ARGUMENT);
Loading history...
223
            }
224
        } else {
225
            switch (strtolower($driver)) {
226
                case 'gd':
227
                    $driver = 'GD';
228
                    break;
229
                case 'imagick':
230
                    $driver = 'Imagick3';
231
                    if (version_compare(PHP_VERSION, '5.0.0', '<')) {
232
                        $driver = 'Imagick2';
233
                    }
234
                    break;
235
                case 'imlib':
236
                    $driver = 'Imlib';
237
                    break;
238
            }
239
        }
240
241
        //        $file = 'Image/Transform/Driver/' . $driver . '.php';
242
        $file = __DIR__ . '/Transform/Driver/' . $driver . '.php';
243
        if (!@fclose(@fopen($file, 'r', true))) {
0 ignored issues
show
Bug introduced by
It seems like @fopen($file, 'r', true) can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

243
        if (!@fclose(/** @scrutinizer ignore-type */ @fopen($file, 'r', true))) {
Loading history...
244
            return PEAR::raiseError('Driver failed to load file ' . $file, IMAGE_TRANSFORM_DRIVER_FILE_MISSING);
245
        }
246
247
        $classname = 'Image_Transform_Driver_' . $driver;
248
249
        if (!class_exists($classname)) {
250
            require_once $file;
251
252
            if (!class_exists($classname)) {
253
                return PEAR::raiseError('Image library ' . $driver . ' not supported... aborting.', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
254
            }
255
        }
256
        $obj = new $classname();
257
258
        // Check startup error
259
        if ($error =& $obj->isError()) {
260
            $obj =& $error;
261
        }
262
263
        return $obj;
264
    }
265
266
    /**
267
     * Returns/sets an error when the instance couldn't initialize properly
268
     *
269
     * @param object $error PEAR_Error object when setting an error
270
     *
271
     * @return mixed FALSE or PEAR_Error object
272
     * @access protected
273
     */
274
    public function &isError($error = null)
275
    {
276
        if (!is_null($error)) {
277
            $this->_error =& $error;
278
        }
279
280
        return $this->_error;
281
    }
282
283
    /**
284
     * Resizes the image in the X and/or Y direction(s)
285
     *
286
     * If either is 0 it will keep the original size for that dimension
287
     *
288
     * @param mixed $new_x   (0, number, percentage 10% or 0.1)
289
     * @param mixed $new_y   (0, number, percentage 10% or 0.1)
290
     * @param array $options Options
291
     *
292
     * @return mixed TRUE or PEAR_Error object on error
293
     * @access public
294
     */
295
    public function resize($new_x = 0, $new_y = 0, $options = null)
296
    {
297
        // 0 means keep original size
298
        $new_x = (0 == $new_x) ? $this->img_x : $this->_parse_size($new_x, $this->img_x);
299
        $new_y = (0 == $new_y) ? $this->img_y : $this->_parse_size($new_y, $this->img_y);
300
301
        // Now do the library specific resizing.
302
        return $this->_resize($new_x, $new_y, $options);
0 ignored issues
show
Unused Code introduced by
The call to Image_Transform::_resize() has too many arguments starting with $new_x. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

302
        return $this->/** @scrutinizer ignore-call */ _resize($new_x, $new_y, $options);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
303
    } // End resize
304
305
    /**
306
     * Scales the image to the specified width
307
     *
308
     * This method preserves the aspect ratio
309
     *
310
     * @param int $new_x Size to scale X-dimension to
311
     *
312
     * @return mixed TRUE or PEAR_Error object on error
313
     * @access public
314
     */
315
    public function scaleByX($new_x)
316
    {
317
        if ($new_x <= 0) {
318
            return PEAR::raiseError('New size must be strictly positive', IMAGE_TRANSFORM_ERROR_OUTOFBOUND);
319
        }
320
        $new_y = round(($new_x / $this->img_x) * $this->img_y, 0);
321
322
        return $this->_resize(max(1, $new_x), max(1, $new_y));
0 ignored issues
show
Unused Code introduced by
The call to Image_Transform::_resize() has too many arguments starting with max(1, $new_x). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

322
        return $this->/** @scrutinizer ignore-call */ _resize(max(1, $new_x), max(1, $new_y));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
323
    } // End scaleByX
324
325
    /**
326
     * Alias for resize()
327
     *
328
     * @see resize()
329
     */
330
    public function scaleByXY($new_x = 0, $new_y = 0, $options = null)
331
    {
332
        return $this->resize($new_x, $new_y, $options);
333
    } // End scaleByXY
334
335
    /**
336
     * Scales the image to the specified height.
337
     *
338
     * This method preserves the aspect ratio
339
     *
340
     * @param int $new_y Size to scale Y-dimension to
341
     *
342
     * @return mixed TRUE or PEAR_Error object on error
343
     * @access public
344
     */
345
    public function scaleByY($new_y)
346
    {
347
        if ($new_y <= 0) {
348
            return PEAR::raiseError('New size must be strictly positive', IMAGE_TRANSFORM_ERROR_OUTOFBOUND);
349
        }
350
        $new_x = round(($new_y / $this->img_y) * $this->img_x, 0);
351
352
        return $this->_resize(max(1, $new_x), max(1, $new_y));
0 ignored issues
show
Unused Code introduced by
The call to Image_Transform::_resize() has too many arguments starting with max(1, $new_x). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

352
        return $this->/** @scrutinizer ignore-call */ _resize(max(1, $new_x), max(1, $new_y));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
353
    } // End scaleByY
354
355
    /**
356
     * Scales an image by a percentage, factor or a given length
357
     *
358
     * This method preserves the aspect ratio
359
     *
360
     * @param mixed $size (number, percentage 10% or 0.1)
361
     *
362
     * @return mixed TRUE or PEAR_Error object on error
363
     * @access public
364
     * @see    scaleByPercentage, scaleByFactor, scaleByLength
365
     */
366
    public function scale($size)
367
    {
368
        if ((strlen($size) > 1) && ('%' == substr($size, -1))) {
369
            return $this->scaleByPercentage(substr($size, 0, -1));
0 ignored issues
show
Bug introduced by
substr($size, 0, -1) of type string is incompatible with the type integer expected by parameter $size of Image_Transform::scaleByPercentage(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

369
            return $this->scaleByPercentage(/** @scrutinizer ignore-type */ substr($size, 0, -1));
Loading history...
370
        } elseif ($size < 1) {
371
            return $this->scaleByFactor($size);
372
        } else {
373
            return $this->scaleByLength($size);
374
        }
375
    } // End scale
376
377
    /**
378
     * Scales an image to a percentage of its original size.  For example, if
379
     * my image was 640x480 and I called scaleByPercentage(10) then the image
380
     * would be resized to 64x48
381
     *
382
     * @param int $size Percentage of original size to scale to
383
     *
384
     * @return mixed TRUE or PEAR_Error object on error
385
     * @access public
386
     */
387
    public function scaleByPercentage($size)
388
    {
389
        return $this->scaleByFactor($size / 100);
390
    } // End scaleByPercentage
391
392
    /**
393
     * Scales an image to a factor of its original size.  For example, if
394
     * my image was 640x480 and I called scaleByFactor(0.5) then the image
395
     * would be resized to 320x240.
396
     *
397
     * @param float $size Factor of original size to scale to
398
     *
399
     * @return mixed TRUE or PEAR_Error object on error
400
     * @access public
401
     */
402
    public function scaleByFactor($size)
403
    {
404
        if ($size <= 0) {
405
            return PEAR::raiseError('New size must be strictly positive', IMAGE_TRANSFORM_ERROR_OUTOFBOUND);
406
        }
407
        $new_x = round($size * $this->img_x, 0);
408
        $new_y = round($size * $this->img_y, 0);
409
410
        return $this->_resize(max(1, $new_x), max(1, $new_y));
0 ignored issues
show
Unused Code introduced by
The call to Image_Transform::_resize() has too many arguments starting with max(1, $new_x). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

410
        return $this->/** @scrutinizer ignore-call */ _resize(max(1, $new_x), max(1, $new_y));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
411
    } // End scaleByFactor
412
413
    /**
414
     * Scales an image so that the longest side has the specified dimension.
415
     *
416
     * This method preserves the aspect ratio
417
     *
418
     * @param int $size Max dimension in pixels
419
     *
420
     * @return mixed TRUE or PEAR_Error object on error
421
     * @access public
422
     */
423
    public function scaleMaxLength($size)
424
    {
425
        if ($size <= 0) {
426
            return PEAR::raiseError('New size must be strictly positive', IMAGE_TRANSFORM_ERROR_OUTOFBOUND);
427
        }
428
        if ($this->img_x >= $this->img_y) {
429
            $new_x = $size;
430
            $new_y = round(($new_x / $this->img_x) * $this->img_y, 0);
431
        } else {
432
            $new_y = $size;
433
            $new_x = round(($new_y / $this->img_y) * $this->img_x, 0);
434
        }
435
436
        return $this->_resize(max(1, $new_x), max(1, $new_y));
0 ignored issues
show
Unused Code introduced by
The call to Image_Transform::_resize() has too many arguments starting with max(1, $new_x). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

436
        return $this->/** @scrutinizer ignore-call */ _resize(max(1, $new_x), max(1, $new_y));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
437
    } // End scaleMaxLength
438
439
    /**
440
     * Alias for scaleMaxLength
441
     *
442
     * @param int $size Max dimension in pixels
443
     *
444
     * @return mixed TRUE or PEAR_Error object on error
445
     * @access public
446
     * @see    scaleMaxLength()
447
     */
448
    public function scaleByLength($size)
449
    {
450
        return $this->scaleMaxLength($size);
451
    }
452
453
    /**
454
     * Fits the image in the specified box size
455
     *
456
     * If the image is bigger than the box specified by $width and $height,
457
     * it will be scaled down to fit inside of it.
458
     * If the image is smaller, nothing is done.
459
     *
460
     * @param integer $width  Width of the box in pixels
461
     * @param integer $height Height of the box in pixels
462
     *
463
     * @return bool|PEAR_Error TRUE or PEAR_Error object on error
464
     * @access public
465
     */
466
    public function fit($width, $height)
467
    {
468
        if ($width <= 0 || $height <= 0) {
469
            return PEAR::raiseError("Invalid arguments.", IMAGE_TRANSFORM_ERROR_ARGUMENT);
470
        }
471
        $x = $this->img_x / $width;
472
        $y = $this->img_y / $height;
473
        if ($x <= 1 && $y <= 1) {
474
            return true;
475
        } elseif ($x > $y) {
476
            return $this->scaleByX($width);
477
        } else {
478
            return $this->scaleByY($height);
479
        }
480
    }
481
482
    /**
483
     * This works as per fit, but creates the canvas of size $width x $height
484
     * and positions the resized image on it, by default in the centre.
485
     *
486
     * @param unknown_type $width
0 ignored issues
show
Bug introduced by
The type unknown_type was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
487
     * @param unknown_type $height
488
     * @param unknown_type $posn
489
     *
490
     * @return unknown
0 ignored issues
show
Bug introduced by
The type unknown was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
491
     */
492
    public function fitOnCanvas($width, $height, $posn = 'center')
0 ignored issues
show
Unused Code introduced by
The parameter $height is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

492
    public function fitOnCanvas($width, /** @scrutinizer ignore-unused */ $height, $posn = 'center')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $width is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

492
    public function fitOnCanvas(/** @scrutinizer ignore-unused */ $width, $height, $posn = 'center')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $posn is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

492
    public function fitOnCanvas($width, $height, /** @scrutinizer ignore-unused */ $posn = 'center')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
493
    {
494
        return PEAR::raiseError('fitOnCanvas() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
495
    }
496
497
    /**
498
     * Fits the image in the specified width
499
     *
500
     * If the image is wider than the width specified by $width,
501
     * it will be scaled down to fit inside of it.
502
     * If the image is smaller, nothing is done.
503
     *
504
     * @param integer $width Maximum width in pixels
505
     *
506
     * @return bool|PEAR_Error TRUE or PEAR_Error object on error
507
     * @access public
508
     */
509
    public function fitX($width)
510
    {
511
        return ($this->img_x <= $width) ? true : $this->scaleByX($width);
512
    }
513
514
    /**
515
     * Fits the image in the specified height
516
     *
517
     * If the image is taller than the height specified by $height,
518
     * it will be scaled down to fit inside of it.
519
     * If the image is smaller, nothing is done.
520
     *
521
     * @param integer $height Maximum height in pixels
522
     *
523
     * @return bool|PEAR_Error TRUE or PEAR_Error object on error
524
     * @access public
525
     */
526
    public function fitY($height)
527
    {
528
        return ($this->img_y <= $height) ? true : $this->scaleByY($height);
529
    }
530
531
    /**
532
     * Sets one options
533
     *
534
     * @param string $name  Name of option
535
     * @param mixed  $value Value of option
536
     *
537
     * @return void
538
     * @access public
539
     * @see    setOptions()
540
     */
541
    public function setOption($name, $value)
542
    {
543
        $this->_options[$name] = $value;
544
    }
545
546
    /**
547
     * Sets multiple options at once
548
     *
549
     * Associative array of options:
550
     *  - quality     (Integer: 0: poor - 100: best)
551
     *  - scaleMethod ('smooth', 'pixel')
552
     *
553
     * @param array $options Array of options
554
     *
555
     * @return void
556
     * @access public
557
     */
558
    public function setOptions($options)
559
    {
560
        $this->_options = array_merge($this->_options, $options);
561
    }
562
563
    /**
564
     * Sets the image type (in lowercase letters), the image height and width.
565
     *
566
     * @param string $image Image filename
567
     *
568
     * @return mixed TRUE or PEAR_error
569
     * @access protected
570
     * @see    PHP_Compat::image_type_to_mime_type()
571
     * @link   http://php.net/getimagesize
572
     */
573
    public function _get_image_details($image)
574
    {
575
        $data = @getimagesize($image);
576
        //  1 = GIF,   2 = JPG,  3 = PNG,  4 = SWF,  5 = PSD,  6 = BMP,
577
        //  7 = TIFF (intel byte order),   8 = TIFF (motorola byte order),
578
        //  9 = JPC,  10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF,
579
        // 15 = WBMP, 16 = XBM
580
        if (!is_array($data)) {
581
            return PEAR::raiseError("Cannot fetch image or images details.", true);
582
        }
583
584
        switch ($data[2]) {
585
            case IMAGETYPE_GIF:
586
                $type = 'gif';
587
                break;
588
            case IMAGETYPE_JPEG:
589
                $type = 'jpeg';
590
                break;
591
            case IMAGETYPE_PNG:
592
                $type = 'png';
593
                break;
594
            case IMAGETYPE_SWF:
595
                $type = 'swf';
596
                break;
597
            case IMAGETYPE_PSD:
598
                $type = 'psd';
599
                break;
600
            case IMAGETYPE_BMP:
601
                $type = 'bmp';
602
                break;
603
            case IMAGETYPE_TIFF_II:
604
            case IMAGETYPE_TIFF_MM:
605
                $type = 'tiff';
606
                break;
607
            case IMAGETYPE_JPC:
608
                $type = 'jpc';
609
                break;
610
            case IMAGETYPE_JP2:
611
                $type = 'jp2';
612
                break;
613
            case IMAGETYPE_JPX:
614
                $type = 'jpx';
615
                break;
616
            case IMAGETYPE_JB2:
617
                $type = 'jb2';
618
                break;
619
            case IMAGETYPE_SWC:
620
                $type = 'swc';
621
                break;
622
            case IMAGETYPE_IFF:
623
                $type = 'iff';
624
                break;
625
            case IMAGETYPE_WBMP:
626
                $type = 'wbmp';
627
                break;
628
            case IMAGETYPE_XBM:
629
                $type = 'xbm';
630
                break;
631
            default:
632
                return PEAR::raiseError("Cannot recognize image format", IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
633
        }
634
        $this->img_x = $this->new_x = $data[0];
635
        $this->img_y = $this->new_y = $data[1];
636
        $this->type  = $type;
637
638
        return true;
639
    }
640
641
    /**
642
     * Returns the matching IMAGETYPE_* constant for a given image type
643
     *
644
     * @param mixed $type String (GIF, JPG,...)
645
     *
646
     * @return mixed string or integer or input on error
647
     * @access protected
648
     * @see    PHP_Compat::image_type_to_mime_type()
649
     **/
650
    public function _convert_image_type($type)
651
    {
652
        switch (strtolower($type)) {
653
            case 'gif':
654
                return IMAGETYPE_GIF;
655
            case 'jpeg':
656
            case 'jpg':
657
                return IMAGETYPE_JPEG;
658
            case 'png':
659
                return IMAGETYPE_PNG;
660
            case 'swf':
661
                return IMAGETYPE_SWF;
662
            case 'psd':
663
                return IMAGETYPE_PSD;
664
            case 'bmp':
665
                return IMAGETYPE_BMP;
666
            case 'tiff':
667
                return IMAGETYPE_TIFF_II;
668
            //IMAGETYPE_TIFF_MM;
669
            case 'jpc':
670
                return IMAGETYPE_JPC;
671
            case 'jp2':
672
                return IMAGETYPE_JP2;
673
            case 'jpx':
674
                return IMAGETYPE_JPX;
675
            case 'jb2':
676
                return IMAGETYPE_JB2;
677
            case 'swc':
678
                return IMAGETYPE_SWC;
679
            case 'iff':
680
                return IMAGETYPE_IFF;
681
            case 'wbmp':
682
                return IMAGETYPE_WBMP;
683
            case 'xbm':
684
                return IMAGETYPE_XBM;
685
            default:
686
                return $type;
687
        }
688
689
        return (isset($types[$t = strtolower($type)])) ? $types[$t] : $type;
0 ignored issues
show
Unused Code introduced by
return IssetNode ? $types[$t] : $type is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
690
    }
691
692
    /**
693
     * Parses input for number format and convert
694
     *
695
     * If either parameter is 0 it will be scaled proportionally
696
     *
697
     * @param mixed $new_size (0, number, percentage 10% or 0.1)
698
     * @param int   $old_size
699
     *
700
     * @return mixed Integer or PEAR_error
701
     * @access protected
702
     */
703
    public function _parse_size($new_size, $old_size)
704
    {
705
        if ('%' == substr($new_size, -1)) {
706
            $new_size = substr($new_size, 0, -1);
707
            $new_size = $new_size / 100;
708
        }
709
        if ($new_size > 1) {
710
            return (int)$new_size;
711
        } elseif (0 == $new_size) {
712
            return (int)$old_size;
713
        } else {
714
            return (int)round($new_size * $old_size, 0);
715
        }
716
    }
717
718
    /**
719
     * Returns an angle between 0 and 360 from any angle value
720
     *
721
     * @param float $angle The angle to normalize
722
     *
723
     * @return float the angle
724
     * @access protected
725
     */
726
    public function _rotation_angle($angle)
727
    {
728
        $angle %= 360;
729
730
        return ($angle < 0) ? $angle + 360 : $angle;
731
    }
732
733
    /**
734
     * Returns the current value of $this->default_text_params.
735
     *
736
     * @return array $this->default_text_params The current text parameters
737
     * @access protected
738
     */
739
    public function _get_default_text_params()
740
    {
741
        return $this->default_text_params;
742
    }
743
744
    /**
745
     * Sets the image width
746
     *
747
     * @param int $size dimension to set
748
     *
749
     * @return void
750
     * @access protected
751
     * @since  29/05/02 13:36:31
752
     */
753
    public function _set_img_x($size)
754
    {
755
        $this->img_x = $size;
756
    }
757
758
    /**
759
     * Sets the image height
760
     *
761
     * @param int $size dimension to set
762
     *
763
     * @return void
764
     * @access protected
765
     * @since  29/05/02 13:36:31
766
     */
767
    public function _set_img_y($size)
768
    {
769
        $this->img_y = $size;
770
    }
771
772
    /**
773
     * Sets the new image width
774
     *
775
     * @param int $size dimension to set
776
     *
777
     * @return void
778
     * @access protected
779
     * @since  29/05/02 13:36:31
780
     */
781
    public function _set_new_x($size)
782
    {
783
        $this->new_x = $size;
784
    }
785
786
    /**
787
     * Sets the new image height
788
     *
789
     * @param int $size dimension to set
790
     *
791
     * @return void
792
     * @since  29/05/02 13:36:31
793
     * @access protected
794
     */
795
    public function _set_new_y($size)
796
    {
797
        $this->new_y = $size;
798
    }
799
800
    /**
801
     * Returns the image handle so that one can further try
802
     * to manipulate the image
803
     *
804
     * @return resource
805
     *
806
     * @access public
807
     */
808
    public function getHandle()
809
    {
810
        return PEAR::raiseError('getHandle() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
811
    }//function getHandle()
812
813
    /**
814
     * Returns the type of the image being manipulated
815
     *
816
     * @return string the image type
817
     * @access public
818
     */
819
    public function getImageType()
820
    {
821
        return $this->type;
822
    }
823
824
    /**
825
     * Returns the MIME type of the image being manipulated
826
     *
827
     * @param string $type Image type to get MIME type for
828
     *
829
     * @return string The MIME type if available, or an empty string
830
     * @access public
831
     * @see    PHP_Compat::image_type_to_mime_type()
832
     * @link   http://php.net/image_type_to_mime_type
833
     */
834
    public function getMimeType($type = null)
835
    {
836
        return image_type_to_mime_type($this->_convert_image_type(($type) ? $type : $this->type));
0 ignored issues
show
Bug introduced by
It seems like $this->_convert_image_ty... ? $type : $this->type) can also be of type string; however, parameter $imagetype of image_type_to_mime_type() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

836
        return image_type_to_mime_type(/** @scrutinizer ignore-type */ $this->_convert_image_type(($type) ? $type : $this->type));
Loading history...
837
    }
838
839
    /**
840
     * Returns the new image width
841
     *
842
     * This function returns the width
843
     * of the new image.
844
     *
845
     * @access public
846
     * @return int  The width of the new image.
847
     */
848
    public function getNewImageWidth()
849
    {
850
        if (isset($this->new_x)) {
851
            return (int)$this->new_x;
852
        }
853
854
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type integer.
Loading history...
855
    }
856
857
    /**
858
     * Return new image Y
859
     *
860
     * This function will retrieve the
861
     * new image 'Y' and return it's value
862
     * if it's set.
863
     *
864
     * @access public
865
     * @return int  The new height of the image.
866
     */
867
    public function getNewImageHeight()
868
    {
869
        if (isset($this->new_y)) {
870
            return (int)$this->new_y;
871
        }
872
873
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type integer.
Loading history...
874
    }
875
876
    /**
877
     * Returns the image width
878
     *
879
     * @return int the width of the image
880
     * @access public
881
     */
882
    public function getImageWidth()
883
    {
884
        return $this->img_x;
885
    }
886
887
    /**
888
     * Returns the image height
889
     *
890
     * @return int the width of the image
891
     * @access public
892
     */
893
    public function getImageHeight()
894
    {
895
        return $this->img_y;
896
    }
897
898
    /**
899
     * Returns the image size and extra format information
900
     *
901
     * @return array The width and height of the image
902
     * @access public
903
     * @see    PHP::getimagesize()
904
     */
905
    public function getImageSize()
906
    {
907
        return array(
908
            $this->img_x,
909
            $this->img_y,
910
            $this->_convert_image_type($this->type),
911
            'height="' . $this->img_y . '" width="' . $this->img_x . '"',
912
            'mime' => $this->getMimeType()
913
        );
914
    }
915
916
    /**
917
     * This looks at the current image type and attempts to determine which
918
     * web-safe format will be most suited.  It does not work brilliantly with
919
     * *.png images, because it is very difficult to know whether they are
920
     * 8-bit or greater.  Guess I need to have fatter code here :-)
921
     *
922
     * @return string web-safe image type
923
     * @access public
924
     */
925
    public function getWebSafeFormat()
926
    {
927
        switch ($this->type) {
928
            case 'gif':
929
            case 'png':
930
                return 'png';
931
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
932
            default:
933
                return 'jpeg';
934
        } // switch
935
    }
936
937
    /**
938
     * Handles space in path and Windows/UNIX difference
939
     *
940
     * @param string $path    Base dir
941
     * @param string $command Command to execute
942
     * @param string $args    Arguments to pass to the command
943
     *
944
     * @return string A prepared string suitable for exec()
945
     * @access protected
946
     */
947
    public function _prepare_cmd($path, $command, $args = '')
948
    {
949
        if (!OS_WINDOWS
950
            || !preg_match('/\s/', $path)) {
951
            return $path . $command . ' ' . $args;
952
        }
953
954
        return 'start /D "' . $path . '" /B ' . $command . ' ' . $args;
955
    }
956
957
    /**
958
     * Place holder for the real resize method
959
     * used by extended methods to do the resizing
960
     *
961
     * @return PEAR_error
962
     * @access protected
963
     */
964
    public function _resize()
965
    {
966
        return PEAR::raiseError('Resize method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
967
    }
968
969
    /**
970
     * Normalizes the colors, gamma and other properties of an image
971
     * (this should give a result equivalent to a Photoshop autolevels)
972
     *
973
     * @return PEAR_error
974
     * @access public
975
     */
976
    public function normalize()
977
    {
978
        return PEAR::raiseError('Normalize method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
979
    }
980
981
    /**
982
     * Loads an image file to work with
983
     *
984
     * Place holder for the real load method
985
     * used by extended methods to do the resizing
986
     *
987
     * @param string $filename Full name of file
988
     *
989
     * @return PEAR_error
990
     * @access public
991
     */
992
    public function load($filename)
993
    {
994
        return PEAR::raiseError('load() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
995
    }
996
997
    /**
998
     * Outputs the image to standard output
999
     *
1000
     * Place holder for the real display method
1001
     * used by extended methods to do the resizing
1002
     *
1003
     * @param string $type    Format of image to save as
1004
     * @param mixed  $quality Format-dependent
1005
     *
1006
     * @return PEAR_error
1007
     * @access public
1008
     */
1009
    public function display($type, $quality = null)
0 ignored issues
show
Unused Code introduced by
The parameter $quality is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1009
    public function display($type, /** @scrutinizer ignore-unused */ $quality = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1010
    {
1011
        return PEAR::raiseError('display() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
1012
    }
1013
1014
    /**
1015
     * Returns if the driver supports a given image type
1016
     *
1017
     * @param string $type Image type (GIF, PNG, JPEG...)
1018
     * @param string $mode 'r' for read, 'w' for write, 'rw' for both
1019
     *
1020
     * @return TRUE if type (and mode) is supported FALSE otherwise
1021
     * @access public
1022
     */
1023
    public function supportsType($type, $mode = 'rw')
1024
    {
1025
        return (false === strpos(@$this->_supported_image_types[strtolower($type)], $mode)) ? false : true;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false === strpos(..., $mode) ? false : true returns the type boolean which is incompatible with the documented return type true.
Loading history...
1026
    }
1027
1028
    /**
1029
     * Saves image to file
1030
     *
1031
     * Place holder for the real save method
1032
     * used by extended methods to do the resizing
1033
     *
1034
     * @param string $filename Filename to save image to
1035
     * @param string $type     Format of image to save as
1036
     * @param mixed  $quality  Format-dependent
1037
     *
1038
     * @return PEAR_error
1039
     * @access public
1040
     */
1041
    public function save($filename, $type, $quality = null)
0 ignored issues
show
Unused Code introduced by
The parameter $filename is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1041
    public function save(/** @scrutinizer ignore-unused */ $filename, $type, $quality = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $quality is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1041
    public function save($filename, $type, /** @scrutinizer ignore-unused */ $quality = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1042
    {
1043
        return PEAR::raiseError('save() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
1044
    }
1045
1046
    /**
1047
     * Releases resource
1048
     *
1049
     * Place holder for the real free method
1050
     * used by extended methods to do the resizing
1051
     *
1052
     * @return PEAR_error
1053
     * @access public
1054
     */
1055
    public function free()
1056
    {
1057
        return PEAR::raiseError('free() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
1058
    }
1059
1060
    /**
1061
     * Converts a color string into an array of RGB values
1062
     *
1063
     * @param string $colorhex A color following the #FFFFFF format
1064
     *
1065
     * @return array 3-element array with 0-255 values
1066
     * @access public
1067
     *
1068
     * @see    rgb2colorname
1069
     * @see    colorarray2colorhex
1070
     */
1071
    public function colorhex2colorarray($colorhex)
1072
    {
1073
        $r = hexdec(substr($colorhex, 1, 2));
1074
        $g = hexdec(substr($colorhex, 3, 2));
1075
        $b = hexdec(substr($colorhex, 5, 2));
1076
1077
        return array($r, $g, $b, 'type' => 'RGB');
1078
    }
1079
1080
    public function _send_display_headers($type)
1081
    {
1082
        // Find the filename of the original image:
1083
        $filename = explode('.', basename($this->image));
1084
        $filename = $filename[0];
1085
        header('Content-type: ' . $this->getMimeType($type));
1086
        header('Content-Disposition: inline; filename=' . $filename . '.' . $type);
1087
    }
1088
1089
    /**
1090
     * Converts an array of RGB value into a #FFFFFF format color.
1091
     *
1092
     * @param array $color 3-element array with 0-255 values
1093
     *
1094
     * @return mixed A color following the #FFFFFF format or FALSE
1095
     *               if the array couldn't be converted
1096
     * @access public
1097
     *
1098
     * @see    rgb2colorname
1099
     * @see    colorhex2colorarray
1100
     */
1101
    public function colorarray2colorhex($color)
1102
    {
1103
        if (!is_array($color)) {
0 ignored issues
show
introduced by
The condition is_array($color) is always true.
Loading history...
1104
            return false;
1105
        }
1106
        $color = sprintf('#%02X%02X%02X', @$color[0], @$color[1], @$color[2]);
1107
1108
        return (7 != strlen($color)) ? false : $color;
1109
    }
1110
1111
    /**
1112
     * Returns the temp directory according to either the TMP, TMPDIR, or TEMP env
1113
     * variables. If these are not set it will also check for the existence of
1114
     * /tmp, %WINDIR%\temp
1115
     *
1116
     * @access public
1117
     * @return string The system tmp directory
1118
     */
1119
    public function getTempDir()
1120
    {
1121
        require_once 'System.php';
1122
1123
        return System::tmpdir();
1124
    }
1125
1126
    /**
1127
     * Returns a temporary filename using tempnam() and the above getTmpDir() function.
1128
     *
1129
     * @param string $dirname Optional directory name for the tmp file
1130
     *
1131
     * @return string Filename and path of the tmp file
1132
     * @access public
1133
     */
1134
    public function getTempFile($dirname = null)
1135
    {
1136
        if (is_null($dirname)) {
1137
            require_once 'System.php';
1138
            $dirname = System::tmpdir();
1139
        }
1140
1141
        return tempnam($dirname, 'temp.');
1142
    }
1143
1144
    public function keepSettingsOnSave($bool)
1145
    {
1146
        $this->keep_settings_on_save = $bool;
1147
    }
1148
1149
    /**
1150
     * Methods to add to the driver classes in the future
1151
     *
1152
     * @return void
1153
     */
1154
    public function addText()
1155
    {
1156
        return PEAR::raiseError('addText() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
1157
    }
1158
1159
    public function addDropShadow()
1160
    {
1161
        return PEAR::raiseError('addDropShadow() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
1162
    }
1163
1164
    public function addBorder()
1165
    {
1166
        return PEAR::raiseError('addBorder() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
1167
    }
1168
1169
    /**
1170
     * Crops an image
1171
     *
1172
     * @param int $width  Cropped image width
1173
     * @param int $height Cropped image height
1174
     * @param int $x      X-coordinate to crop at
1175
     * @param int $y      Y-coordinate to crop at
1176
     *
1177
     * @return mixed TRUE or a PEAR_Error object on error
1178
     * @access public
1179
     **/
1180
    public function crop($width, $height, $x = 0, $y = 0)
1181
    {
1182
        return PEAR::raiseError('crop() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
1183
    }
1184
1185
    public function canvasResize()
1186
    {
1187
        return PEAR::raiseError('canvasResize() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
1188
    }
1189
1190
    /**
1191
     * Corrects the gamma of an image
1192
     *
1193
     * @param float $outputgamma Gamma correction factor
1194
     *
1195
     * @return mixed TRUE or a PEAR_error object on error
1196
     * @access public
1197
     **/
1198
    public function gamma($outputgamma = 1.0)
0 ignored issues
show
Unused Code introduced by
The parameter $outputgamma is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1198
    public function gamma(/** @scrutinizer ignore-unused */ $outputgamma = 1.0)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1199
    {
1200
        return PEAR::raiseError('gamma() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
1201
    }
1202
1203
    /**
1204
     * Rotates the image clockwise
1205
     *
1206
     * @param float $angle   Angle of rotation in degres
1207
     * @param mixed $options Rotation options
1208
     *
1209
     * @return bool|PEAR_Error TRUE on success, PEAR_Error object on error
1210
     * @access public
1211
     */
1212
    public function rotate($angle, $options = null)
1213
    {
1214
        return PEAR::raiseError('rotate() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
1215
    }
1216
1217
    /**
1218
     * Horizontal mirroring
1219
     *
1220
     * @return mixed TRUE or PEAR_Error object on error
1221
     * @access public
1222
     * @see    flip()
1223
     **/
1224
    public function mirror()
1225
    {
1226
        return PEAR::raiseError('mirror() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
1227
    }
1228
1229
    /**
1230
     * Vertical mirroring
1231
     *
1232
     * @return TRUE or PEAR Error object on error
1233
     * @access public
1234
     * @see    mirror()
1235
     **/
1236
    public function flip()
1237
    {
1238
        return PEAR::raiseError('flip() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
1239
    }
1240
1241
    /**
1242
     * Converts an image into greyscale colors
1243
     *
1244
     * @return mixed TRUE or a PEAR error object on error
1245
     * @access public
1246
     **/
1247
    public function greyscale()
1248
    {
1249
        return PEAR::raiseError('greyscale() method not supported by driver', IMAGE_TRANSFORM_ERROR_UNSUPPORTED);
1250
    }
1251
1252
    /**
1253
     * Converts an image into greyscale colors
1254
     *
1255
     * @return mixed TRUE or a PEAR error object on error
1256
     * @see greyscale()
1257
     **/
1258
    public function grayscale()
1259
    {
1260
        return $this->greyscale();
1261
    }
1262
1263
    /**
1264
     * Returns a color option
1265
     *
1266
     * @param string $colorOf one of 'canvasColor', 'pencilColor', 'fontColor'
1267
     * @param array  $options configuration options
1268
     * @param array  $default default value to return if color not found
1269
     *
1270
     * @return array an RGB color array
1271
     * @access protected
1272
     */
1273
    public function _getColor($colorOf, $options = array(), $default = array(0, 0, 0))
1274
    {
1275
        $opt = array_merge($this->_options, (array)$options);
1276
        if (isset($opt[$colorOf])) {
1277
            $color = $opt[$colorOf];
1278
            if (is_array($color)) {
1279
                return $color;
1280
            }
1281
            if ('#' == $color{0}) {
1282
                return $this->colorhex2colorarray($color);
1283
            }
1284
            static $colornames = array();
1285
            require_once 'Image/Transform/Driver/ColorsDefs.php';
1286
1287
            return (isset($colornames[$color])) ? $colornames[$color] : $default;
1288
        }
1289
1290
        return $default;
1291
    }
1292
1293
    /**
1294
     * Returns an option
1295
     *
1296
     * @param string $name    name of option
1297
     * @param array  $options local override option array
1298
     * @param mixed  $default default value to return if option is not found
1299
     *
1300
     * @return mixed the option
1301
     * @access protected
1302
     */
1303
    public function _getOption($name, $options = array(), $default = null)
1304
    {
1305
        $opt = array_merge($this->_options, (array)$options);
1306
1307
        return (isset($opt[$name])) ? $opt[$name] : $default;
1308
    }
1309
1310
    /**
1311
     * Checks if the rectangle passed intersects with the current image
1312
     *
1313
     * @param int $width  Width of rectangle
1314
     * @param int $height Height of rectangle
1315
     * @param int $x      X-coordinate
1316
     * @param int $y      Y-coordinate
1317
     *
1318
     * @return bool|PEAR_Error TRUE if intersects, FALSE if not,
1319
     *                         and PEAR_Error on error
1320
     * @access public
1321
     */
1322
    public function intersects($width, $height, $x, $y)
1323
    {
1324
        $left  = $x;
1325
        $right = $x + $width;
1326
        if ($right < $left) {
1327
            $left  = $right;
1328
            $right = $x;
1329
        }
1330
        $top    = $y;
1331
        $bottom = $y + $height;
1332
        if ($bottom < $top) {
1333
            $top    = $bottom;
1334
            $bottom = $y;
1335
        }
1336
1337
        return (bool)($left < $this->new_x
1338
                      && $right >= 0
1339
                      && $top < $this->new_y
1340
                      && $bottom >= 0);
1341
    }
1342
}
1343