Passed
Branch master (f2d2e3)
by Michael
18:45
created

Image_Transform_Driver_GD::rotate()   F

Complexity

Conditions 32
Paths 2305

Size

Total Lines 174

Duplication

Lines 112
Ratio 64.37 %

Importance

Changes 0
Metric Value
cc 32
nc 2305
nop 2
dl 112
loc 174
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/***********************************************************************
3
** Title.........:  GD Driver
4
** Version.......:  1.0
5
** Author........:  Xiang Wei ZHUO <[email protected]>
6
** Filename......:  GD.php
7
** Last changed..:  30 Aug 2003 
8
** Notes.........:  Orginal is from PEAR
9
**/
10
// +----------------------------------------------------------------------+
11
// | PHP Version 4                                                        |
12
// +----------------------------------------------------------------------+
13
// | Copyright (c) 1997-2002 The PHP Group                                |
14
// +----------------------------------------------------------------------+
15
// | This source file is subject to version 2.02 of the PHP license,      |
16
// | that is bundled with this package in the file LICENSE, and is        |
17
// | available at through the world-wide-web at                           |
18
// | http://www.php.net/license/2_02.txt.                                 |
19
// | If you did not receive a copy of the PHP license and are unable to   |
20
// | obtain it through the world-wide-web, please send a note to          |
21
// | [email protected] so we can mail you a copy immediately.               |
22
// +----------------------------------------------------------------------+
23
// | Authors: Peter Bowyer <[email protected]>                      |
24
// |          Alan Knowles <[email protected]>                            |
25
// +----------------------------------------------------------------------+
26
//
27
//    Usage :
28
//    $img    = new Image_Transform_GD();
29
//    $angle  = -78;
30
//    $img->load('magick.png');
31
//
32
//    if($img->rotate($angle,array('autoresize'=>true,'color_mask'=>array(255,0,0)))){
33
//        $img->addText(array('text'=>"Rotation $angle",'x'=>0,'y'=>100,'font'=>'/usr/share/fonts/default/TrueType/cogb____.ttf'));
34
//        $img->display();
35
//    } else {
36
//        echo "Error";
37
//    }
38
//
39
//
40
// $Id: GD.php 26 2004-03-31 02:35:21Z Wei Zhuo $
41
//
42
// Image Transformation interface using the GD library
43
//
44
45
require_once "Transform.php";
46
47
Class Image_Transform_Driver_GD extends Image_Transform
48
{
49
    /**
50
     * Holds the image file for manipulation
51
     */
52
    var $imageHandle = '';
53
54
    /**
55
     * Holds the original image file
56
     */
57
    var $old_image = '';
58
59
    /**
60
     * Check settings
61
     *
62
     * @return mixed true or  or a PEAR error object on error
63
     *
64
     * @see PEAR::isError()
65
     */
66
    function Image_Transform_GD()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
67
    {
68
        return;
69
    } // End function Image
70
71
    /**
72
     * Load image
73
     *
74
     * @param string filename
0 ignored issues
show
Bug introduced by
The type filename 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...
75
     *
76
     * @return mixed none or a PEAR error object on error
77
     * @see PEAR::isError()
78
     */
79
    function load($image)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
80
    {
81
        $this->uid = md5($_SERVER['REMOTE_ADDR']);
82
        $this->image = $image;
83
        $this->_get_image_details($image);
84
        $functionName = 'ImageCreateFrom' . $this->type;
85
		if(function_exists($functionName))
86
		{
87
			$this->imageHandle = $functionName($this->image);
88
		}
89
    } // End load
90
91
    /**
92
     * addText
93
     *
94
     * @param   array   options     Array contains options
0 ignored issues
show
Bug introduced by
The type options 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...
95
     *                              array(
96
     *                                  'text'  The string to draw
97
     *                                  'x'     Horizontal position
98
     *                                  'y'     Vertical Position
99
     *                                  'Color' Font color
100
     *                                  'font'  Font to be used
101
     *                                  'size'  Size of the fonts in pixel
102
     *                                  'resize_first'  Tell if the image has to be resized
103
     *                                                  before drawing the text
104
     *                              )
105
     *
106
     * @return none
0 ignored issues
show
Bug introduced by
The type none 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...
107
     * @see PEAR::isError()
108
     */
109
    function addText($params)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
110
    {
111
        $default_params = array(
112
                                'text' => 'This is Text',
113
                                'x' => 10,
114
                                'y' => 20,
115
                                'color' => array(255,0,0),
116
                                'font' => 'Arial.ttf',
117
                                'size' => '12',
118
                                'angle' => 0,
119
                                'resize_first' => false // Carry out the scaling of the image before annotation?  Not used for GD
120
                                );
121
        $params = array_merge($default_params, $params);
122
        extract($params);
123
124
        if( !is_array($color) ){
125
            if ($color[0]=='#'){
126
                $this->colorhex2colorarray( $color );
127
            } else {
128
                include_once('Image/Transform/Driver/ColorsDefs.php');
129
                $color = isset($colornames[$color])?$colornames[$color]:false;
130
            }
131
        }
132
133
        $c = imagecolorresolve ($this->imageHandle, $color[0], $color[1], $color[2]);
0 ignored issues
show
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $image of imagecolorresolve(). ( Ignorable by Annotation )

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

133
        $c = imagecolorresolve (/** @scrutinizer ignore-type */ $this->imageHandle, $color[0], $color[1], $color[2]);
Loading history...
134
135
        if ('ttf' == substr($font, -3)) {
136
            ImageTTFText($this->imageHandle, $size, $angle, $x, $y, $c, $font, $text);
0 ignored issues
show
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $image of imagettftext(). ( Ignorable by Annotation )

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

136
            ImageTTFText(/** @scrutinizer ignore-type */ $this->imageHandle, $size, $angle, $x, $y, $c, $font, $text);
Loading history...
137
        } else {
138
            ImagePSText($this->imageHandle, $size, $angle, $x, $y, $c, $font, $text);
0 ignored issues
show
Deprecated Code introduced by
The function imagepstext() has been deprecated: 7.0.0 This function was REMOVED in PHP 7.0.0. ( Ignorable by Annotation )

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

138
            /** @scrutinizer ignore-deprecated */ ImagePSText($this->imageHandle, $size, $angle, $x, $y, $c, $font, $text);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $image of imagepstext(). ( Ignorable by Annotation )

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

138
            ImagePSText(/** @scrutinizer ignore-type */ $this->imageHandle, $size, $angle, $x, $y, $c, $font, $text);
Loading history...
139
        }
140
        return true;
0 ignored issues
show
Bug Best Practice introduced by
The expression return true returns the type true which is incompatible with the documented return type none.
Loading history...
141
    } // End addText
142
143
144
    /**
145
     * Rotate image by the given angle
146
     * Uses a fast rotation algorythm for custom angles
147
     * or lines copy for multiple of 90 degrees
148
     *
149
     * @param int       $angle      Rotation angle
150
     * @param array     $options    array(  'autoresize'=>true|false,
151
     *                                      'color_mask'=>array(r,g,b), named color or #rrggbb
152
     *                                   )
153
     * @author Pierre-Alain Joye
154
     * @return mixed none or a PEAR error object on error
155
     * @see PEAR::isError()
156
     */
157
    function rotate($angle, $options=null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
158
    {
159
        if(function_exists('imagerotate') && false) {
160
            $white = imagecolorallocate ($this->imageHandle, 255, 255, 255);
0 ignored issues
show
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $image of imagecolorallocate(). ( Ignorable by Annotation )

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

160
            $white = imagecolorallocate (/** @scrutinizer ignore-type */ $this->imageHandle, 255, 255, 255);
Loading history...
161
			$this->imageHandle = imagerotate($this->imageHandle, $angle, $white);
0 ignored issues
show
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $image of imagerotate(). ( Ignorable by Annotation )

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

161
			$this->imageHandle = imagerotate(/** @scrutinizer ignore-type */ $this->imageHandle, $angle, $white);
Loading history...
162
            return true;
163
        }
164
165
        if ( $options==null ){
166
            $autoresize = true;
167
            $color_mask = array(255,255,0);
168
        } else {
169
            extract( $options );
170
        }
171
172
        while ($angle <= -45) {
173
            $angle  += 360;
174
        }
175
        while ($angle > 270) {
176
            $angle  -= 360;
177
        }
178
179
        $t      = deg2rad($angle);
180
181
        if( !is_array($color_mask) ){
182
            if ($color[0]=='#'){
183
                $this->colorhex2colorarray( $color_mask );
184
            } else {
185
                include_once('Image/Transform/Driver/ColorDefs.php');
186
                $color = isset($colornames[$color_mask])?$colornames[$color_mask]:false;
0 ignored issues
show
Unused Code introduced by
The assignment to $color is dead and can be removed.
Loading history...
187
            }
188
        }
189
190
        // Do not round it, too much lost of quality
191
        $cosT   = cos($t);
192
        $sinT   = sin($t);
193
194
        $img    =& $this->imageHandle;
195
196
        $width  = $max_x  = $this->img_x;
197
        $height = $max_y  = $this->img_y;
198
        $min_y  = 0;
199
        $min_x  = 0;
200
201
        $x1     = round($max_x/2,0);
202
        $y1     = round($max_y/2,0);
203
204
        if ( $autoresize ){
205
            $t      = abs($t);
206
            $a      = round($angle,0);
0 ignored issues
show
Unused Code introduced by
The assignment to $a is dead and can be removed.
Loading history...
207
            switch((int)($angle)){
208
                case 0:
209
                        $width2     = $width;
210
                        $height2    = $height;
211
                    break;
212
                case 90:
213
                        $width2     = $height;
214
                        $height2    = $width;
215
                    break;
216
                case 180:
217
                        $width2     = $width;
218
                        $height2    = $height;
219
                    break;
220
                case 270:
221
                        $width2     = $height;
222
                        $height2    = $width;
223
                    break;
224
                default:
225
                    $width2     = (int)(abs(sin($t) * $height + cos($t) * $width));
226
                    $height2    = (int)(abs(cos($t) * $height+sin($t) * $width));
227
            }
228
229
            $width2     -= $width2%2;
230
            $height2    -= $height2%2;
231
232
            $d_width    = abs($width - $width2);
233
            $d_height   = abs($height - $height2);
234
            $x_offset   = $d_width/2;
235
            $y_offset   = $d_height/2;
236
            $min_x2     = -abs($x_offset);
237
            $min_y2     = -abs($y_offset);
238
            $max_x2     = $width2;
239
            $max_y2     = $height2;
240
        }
241
242
        if(function_exists('ImageCreateTrueColor')){
243
            $img2 =ImageCreateTrueColor($width2,$height2);
244
        } else {
245
            $img2 =ImageCreate($width2,$height2);
246
        }
247
	
248
249
        if ( !is_resource($img2) ){
250
            return false;/*PEAR::raiseError('Cannot create buffer for the rotataion.',
251
                                null, PEAR_ERROR_TRIGGER, E_USER_NOTICE);*/
252
        }
253
254
        $this->img_x = $width2;
255
        $this->img_y = $height2;
256
257
258
        imagepalettecopy($img2,$img);
0 ignored issues
show
Bug introduced by
$img of type string is incompatible with the type resource expected by parameter $source of imagepalettecopy(). ( Ignorable by Annotation )

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

258
        imagepalettecopy($img2,/** @scrutinizer ignore-type */ $img);
Loading history...
259
260
        $mask   = imagecolorresolve($img2,$color_mask[0],$color_mask[1],$color_mask[2]);
261
262
        // use simple lines copy for axes angles
263
        switch((int)($angle)){
264
            case 0:
265
                imagefill ($img2, 0, 0,$mask);
266
                for ($y=0; $y < $max_y; $y++) {
267
                    for ($x = $min_x; $x < $max_x; $x++){
268
                        $c  = @imagecolorat ( $img, $x, $y);
0 ignored issues
show
Bug introduced by
$img of type string is incompatible with the type resource expected by parameter $image of imagecolorat(). ( Ignorable by Annotation )

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

268
                        $c  = @imagecolorat ( /** @scrutinizer ignore-type */ $img, $x, $y);
Loading history...
269
                        imagesetpixel($img2,$x+$x_offset,$y+$y_offset,$c);
270
                    }
271
                }
272
                break;
273
            case 90:
274
                imagefill ($img2, 0, 0,$mask);
275
                for ($x = $min_x; $x < $max_x; $x++){
276
                    for ($y=$min_y; $y < $max_y; $y++) {
277
                        $c  = imagecolorat ( $img, $x, $y);
278
                        imagesetpixel($img2,$max_y-$y-1,$x,$c);
279
                    }
280
                }
281
                break;
282
            case 180:
283
                imagefill ($img2, 0, 0,$mask);
284
                for ($y=0; $y < $max_y; $y++) {
285
                    for ($x = $min_x; $x < $max_x; $x++){
286
                        $c  = @imagecolorat ( $img, $x, $y);
287
                        imagesetpixel($img2, $max_x2-$x-1, $max_y2-$y-1, $c);
288
                    }
289
                }
290
                break;
291
            case 270:
292
                imagefill ($img2, 0, 0,$mask);
293
                for ($y=0; $y < $max_y; $y++) {
294
                    for ($x = $max_x; $x >= $min_x; $x--){
295
                        $c  = @imagecolorat ( $img, $x, $y);
296
                        imagesetpixel($img2,$y,$max_x-$x-1,$c);
297
                    }
298
                }
299
                break;
300
            // simple reverse rotation algo
301
            default:
302
                $i=0;
0 ignored issues
show
Unused Code introduced by
The assignment to $i is dead and can be removed.
Loading history...
303
                for ($y = $min_y2; $y < $max_y2; $y++){
304
305
                    // Algebra :)
306
                    $x2 = round((($min_x2-$x1) * $cosT) + (($y-$y1) * $sinT + $x1),0);
307
                    $y2 = round((($y-$y1) * $cosT - ($min_x2-$x1) * $sinT + $y1),0);
308
309
                    for ($x = $min_x2; $x < $max_x2; $x++){
310
311
                        // Check if we are out of original bounces, if we are
312
                        // use the default color mask
313
                        if ( $x2>=0 && $x2<$max_x && $y2>=0 && $y2<$max_y ){
314
                            $c  = imagecolorat ( $img, $x2, $y2);
0 ignored issues
show
Bug introduced by
$y2 of type double is incompatible with the type integer expected by parameter $y of imagecolorat(). ( Ignorable by Annotation )

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

314
                            $c  = imagecolorat ( $img, $x2, /** @scrutinizer ignore-type */ $y2);
Loading history...
Bug introduced by
$x2 of type double is incompatible with the type integer expected by parameter $x of imagecolorat(). ( Ignorable by Annotation )

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

314
                            $c  = imagecolorat ( $img, /** @scrutinizer ignore-type */ $x2, $y2);
Loading history...
315
                        } else {
316
                            $c  = $mask;
317
                        }
318
                        imagesetpixel($img2,$x+$x_offset,$y+$y_offset,$c);
319
320
                        // round verboten!
321
                        $x2  += $cosT;
322
                        $y2  -= $sinT;
323
                    }
324
                }
325
                break;
326
        }
327
        $this->old_image    = $this->imageHandle;
328
        $this->imageHandle  =  $img2;
329
        return true;
330
    }
331
332
333
   /**
334
    * Resize Action
335
    *
336
    * For GD 2.01+ the new copyresampled function is used
337
    * It uses a bicubic interpolation algorithm to get far
338
    * better result.
339
    *
340
    * @param $new_x int  new width
341
    * @param $new_y int  new height
342
    *
343
    * @return true on success or pear error
344
    * @see PEAR::isError()
345
    */
346
    function _resize($new_x, $new_y) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
347
        if ($this->resized === true) {
348
            return false; /*PEAR::raiseError('You have already resized the image without saving it.  Your previous resizing will be overwritten', null, PEAR_ERROR_TRIGGER, E_USER_NOTICE);*/
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 true.
Loading history...
349
        }
350
        if(function_exists('ImageCreateTrueColor')){
351
            $new_img =ImageCreateTrueColor($new_x,$new_y);
352
        } else {
353
            $new_img =ImageCreate($new_x,$new_y);
354
        }
355
        if(function_exists('ImageCopyResampled')){
356
            ImageCopyResampled($new_img, $this->imageHandle, 0, 0, 0, 0, $new_x, $new_y, $this->img_x, $this->img_y);
0 ignored issues
show
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $src_image of imagecopyresampled(). ( Ignorable by Annotation )

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

356
            ImageCopyResampled($new_img, /** @scrutinizer ignore-type */ $this->imageHandle, 0, 0, 0, 0, $new_x, $new_y, $this->img_x, $this->img_y);
Loading history...
Bug introduced by
It seems like $new_img can also be of type false; however, parameter $dst_image of imagecopyresampled() 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

356
            ImageCopyResampled(/** @scrutinizer ignore-type */ $new_img, $this->imageHandle, 0, 0, 0, 0, $new_x, $new_y, $this->img_x, $this->img_y);
Loading history...
357
        } else {
358
            ImageCopyResized($new_img, $this->imageHandle, 0, 0, 0, 0, $new_x, $new_y, $this->img_x, $this->img_y);
0 ignored issues
show
Bug introduced by
It seems like $new_img can also be of type false; however, parameter $dst_image of imagecopyresized() 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

358
            ImageCopyResized(/** @scrutinizer ignore-type */ $new_img, $this->imageHandle, 0, 0, 0, 0, $new_x, $new_y, $this->img_x, $this->img_y);
Loading history...
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $src_image of imagecopyresized(). ( Ignorable by Annotation )

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

358
            ImageCopyResized($new_img, /** @scrutinizer ignore-type */ $this->imageHandle, 0, 0, 0, 0, $new_x, $new_y, $this->img_x, $this->img_y);
Loading history...
359
        }
360
        $this->old_image = $this->imageHandle;
361
        $this->imageHandle = $new_img;
362
        $this->resized = true;
363
364
        $this->new_x = $new_x;
365
        $this->new_y = $new_y;
366
        return true;
367
    }
368
369
    /**
370
     * Crop the image
371
     *
372
     * @param int $crop_x left column of the image
373
     * @param int $crop_y top row of the image
374
     * @param int $crop_width new cropped image width
375
     * @param int $crop_height new cropped image height
376
     */
377
    function crop($new_x, $new_y, $new_width, $new_height) 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
378
    {
379
        if(function_exists('ImageCreateTrueColor')){
380
            $new_img =ImageCreateTrueColor($new_width,$new_height);
381
        } else {
382
            $new_img =ImageCreate($new_width,$new_height);
383
        }
384
        if(function_exists('ImageCopyResampled')){
385
            ImageCopyResampled($new_img, $this->imageHandle, 0, 0, $new_x, $new_y,$new_width,$new_height,$new_width,$new_height);
0 ignored issues
show
Bug introduced by
It seems like $new_img can also be of type false; however, parameter $dst_image of imagecopyresampled() 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

385
            ImageCopyResampled(/** @scrutinizer ignore-type */ $new_img, $this->imageHandle, 0, 0, $new_x, $new_y,$new_width,$new_height,$new_width,$new_height);
Loading history...
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $src_image of imagecopyresampled(). ( Ignorable by Annotation )

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

385
            ImageCopyResampled($new_img, /** @scrutinizer ignore-type */ $this->imageHandle, 0, 0, $new_x, $new_y,$new_width,$new_height,$new_width,$new_height);
Loading history...
386
        } else {
387
            ImageCopyResized($new_img, $this->imageHandle, 0, 0, $new_x, $new_y, $new_width,$new_height,$new_width,$new_height);
0 ignored issues
show
Bug introduced by
It seems like $new_img can also be of type false; however, parameter $dst_image of imagecopyresized() 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

387
            ImageCopyResized(/** @scrutinizer ignore-type */ $new_img, $this->imageHandle, 0, 0, $new_x, $new_y, $new_width,$new_height,$new_width,$new_height);
Loading history...
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $src_image of imagecopyresized(). ( Ignorable by Annotation )

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

387
            ImageCopyResized($new_img, /** @scrutinizer ignore-type */ $this->imageHandle, 0, 0, $new_x, $new_y, $new_width,$new_height,$new_width,$new_height);
Loading history...
388
        }
389
        $this->old_image = $this->imageHandle;
390
        $this->imageHandle = $new_img;
391
        $this->resized = true;
392
393
        $this->new_x = $new_x;
394
        $this->new_y = $new_y;
395
        return true;
396
    }
397
   
398
    /**
399
     * Flip the image horizontally or vertically
400
     *
401
     * @param boolean $horizontal true if horizontal flip, vertical otherwise
402
     */
403
    function flip($horizontal)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
404
    {
405
        if(!$horizontal) {
406
            $this->rotate(180);
407
        }
408
409
        $width = imagesx($this->imageHandle); 
0 ignored issues
show
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $image of imagesx(). ( Ignorable by Annotation )

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

409
        $width = imagesx(/** @scrutinizer ignore-type */ $this->imageHandle); 
Loading history...
410
        $height = imagesy($this->imageHandle); 
0 ignored issues
show
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $image of imagesy(). ( Ignorable by Annotation )

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

410
        $height = imagesy(/** @scrutinizer ignore-type */ $this->imageHandle); 
Loading history...
411
412
        for ($j = 0; $j < $height; $j++) { 
413
                $left = 0; 
414
                $right = $width-1; 
415
416
417
                while ($left < $right) { 
418
                    //echo " j:".$j." l:".$left." r:".$right."\n<br>";
419
                    $t = imagecolorat($this->imageHandle, $left, $j); 
0 ignored issues
show
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $image of imagecolorat(). ( Ignorable by Annotation )

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

419
                    $t = imagecolorat(/** @scrutinizer ignore-type */ $this->imageHandle, $left, $j); 
Loading history...
420
                    imagesetpixel($this->imageHandle, $left, $j, imagecolorat($this->imageHandle, $right, $j)); 
0 ignored issues
show
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $image of imagesetpixel(). ( Ignorable by Annotation )

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

420
                    imagesetpixel(/** @scrutinizer ignore-type */ $this->imageHandle, $left, $j, imagecolorat($this->imageHandle, $right, $j)); 
Loading history...
421
                    imagesetpixel($this->imageHandle, $right, $j, $t); 
422
                    $left++; $right--; 
423
                } 
424
            
425
        }
426
427
        return true;
428
    }
429
430
431
    /**
432
     * Adjust the image gamma
433
     *
434
     * @param float $outputgamma
435
     *
436
     * @return none
437
     */
438
    function gamma($outputgamma=1.0) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
439
        ImageGammaCorrect($this->imageHandle, 1.0, $outputgamma);
0 ignored issues
show
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $image of imagegammacorrect(). ( Ignorable by Annotation )

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

439
        ImageGammaCorrect(/** @scrutinizer ignore-type */ $this->imageHandle, 1.0, $outputgamma);
Loading history...
440
    }
441
442
    /**
443
     * Save the image file
444
     *
445
     * @param $filename string  the name of the file to write to
446
     * @param $quality  int     output DPI, default is 85
447
     * @param $types    string  define the output format, default
448
     *                          is the current used format
449
     *
450
     * @return none
451
     */
452
    function save($filename, $type = '', $quality = 85)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
453
    {
454
		$type           = $type==''? $this->type : $type;
455
		$functionName   = 'image' . $type;
456
457
		if(function_exists($functionName))
458
		{
459
			$this->old_image = $this->imageHandle;
460
			if($type=='jpeg')
461
				$functionName($this->imageHandle, $filename, $quality);
462
			else
463
				$functionName($this->imageHandle, $filename);
464
			$this->imageHandle = $this->old_image;
465
			$this->resized = false;
466
		}
467
    } // End save
468
469
470
    /**
471
     * Display image without saving and lose changes
472
     *
473
     * @param string type (JPG,PNG...);
474
     * @param int quality 75
0 ignored issues
show
Bug introduced by
The type quality 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...
475
     *
476
     * @return none
477
     */
478
    function display($type = '', $quality = 75)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
479
    {
480
        if ($type != '') {
481
            $this->type = $type;
482
        }
483
        $functionName = 'Image' . $this->type;
484
		if(function_exists($functionName))
485
		{
486
			header('Content-type: image/' . strtolower($this->type));
487
			$functionName($this->imageHandle, '', $quality);
488
			$this->imageHandle = $this->old_image;
489
			$this->resized = false;
490
			ImageDestroy($this->old_image);
0 ignored issues
show
Bug introduced by
$this->old_image of type string is incompatible with the type resource expected by parameter $image of imagedestroy(). ( Ignorable by Annotation )

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

490
			ImageDestroy(/** @scrutinizer ignore-type */ $this->old_image);
Loading history...
491
			$this->free();
492
		}
493
    }
494
495
    /**
496
     * Destroy image handle
497
     *
498
     * @return none
499
     */
500
    function free()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
501
    {
502
        if ($this->imageHandle){
503
            ImageDestroy($this->imageHandle);
0 ignored issues
show
Bug introduced by
$this->imageHandle of type string is incompatible with the type resource expected by parameter $image of imagedestroy(). ( Ignorable by Annotation )

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

503
            ImageDestroy(/** @scrutinizer ignore-type */ $this->imageHandle);
Loading history...
504
        }
505
    }
506
507
} // End class ImageGD
508
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
509