Issues (1270)

lib/phpqrcode/qrimage.php (11 issues)

1
<?php
2
/*
3
 * PHP QR Code encoder
4
 *
5
 * Image output of code using GD2
6
 *
7
 * PHP QR Code is distributed under LGPL 3
8
 * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
9
 *
10
 * This library is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU Lesser General Public
12
 * License as published by the Free Software Foundation; either
13
 * version 3 of the License, or any later version.
14
 *
15
 * This library is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
 * Lesser General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Lesser General Public
21
 * License along with this library; if not, write to the Free Software
22
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
 */
24
 
25
    define('QR_IMAGE', true);
26
27
    class QRimage {
28
    
29
        //----------------------------------------------------------------------
30
        public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = false) 
31
        {
32
            $image = self::image($frame, $pixelPerPoint, $outerFrame);
33
            
34
            if ($filename === false) {
35
                Header("Content-type: image/png");
36
                ImagePng($image);
0 ignored issues
show
It seems like $image can also be of type false; however, parameter $image of imagepng() 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

36
                ImagePng(/** @scrutinizer ignore-type */ $image);
Loading history...
37
            } else {
38
                if ($saveandprint === true) {
39
                    ImagePng($image, $filename);
40
                    header("Content-type: image/png");
41
                    ImagePng($image);
42
                } else {
43
                    ImagePng($image, $filename);
44
                }
45
            }
46
            
47
            ImageDestroy($image);
0 ignored issues
show
It seems like $image can also be of type false; however, parameter $image of imagedestroy() 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

47
            ImageDestroy(/** @scrutinizer ignore-type */ $image);
Loading history...
48
        }
49
    
50
        //----------------------------------------------------------------------
51
        public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) 
52
        {
53
            $image = self::image($frame, $pixelPerPoint, $outerFrame);
54
            
55
            if ($filename === false) {
56
                Header("Content-type: image/jpeg");
57
                ImageJpeg($image, null, $q);
0 ignored issues
show
It seems like $image can also be of type false; however, parameter $image of imagejpeg() 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

57
                ImageJpeg(/** @scrutinizer ignore-type */ $image, null, $q);
Loading history...
58
            } else {
59
                ImageJpeg($image, $filename, $q);            
60
            }
61
            
62
            ImageDestroy($image);
0 ignored issues
show
It seems like $image can also be of type false; however, parameter $image of imagedestroy() 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

62
            ImageDestroy(/** @scrutinizer ignore-type */ $image);
Loading history...
63
        }
64
    
65
        //----------------------------------------------------------------------
66
        private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) 
67
        {
68
            $h = count($frame);
69
            $w = strlen($frame[0]);
70
            
71
            $imgW = $w + 2 * $outerFrame;
72
            $imgH = $h + 2 * $outerFrame;
73
            
74
            $base_image = ImageCreate($imgW, $imgH);
75
            
76
            $col[0] = ImageColorAllocate($base_image, 255, 255, 255);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$col was never initialized. Although not strictly required by PHP, it is generally a good practice to add $col = array(); before regardless.
Loading history...
It seems like $base_image can also be of type false; however, parameter $image of imagecolorallocate() 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

76
            $col[0] = ImageColorAllocate(/** @scrutinizer ignore-type */ $base_image, 255, 255, 255);
Loading history...
77
            $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
78
79
            imagefill($base_image, 0, 0, $col[0]);
0 ignored issues
show
It seems like $base_image can also be of type false; however, parameter $image of imagefill() 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

79
            imagefill(/** @scrutinizer ignore-type */ $base_image, 0, 0, $col[0]);
Loading history...
80
81
            for ($y = 0; $y < $h; $y++) {
82
                for ($x = 0; $x < $w; $x++) {
83
                    if ($frame[$y][$x] == '1') {
84
                        ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); 
0 ignored issues
show
It seems like $base_image can also be of type false; however, parameter $image of imagesetpixel() 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

84
                        ImageSetPixel(/** @scrutinizer ignore-type */ $base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); 
Loading history...
85
                    }
86
                }
87
            }
88
            
89
            $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
90
            ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
0 ignored issues
show
It seems like $target_image 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

90
            ImageCopyResized(/** @scrutinizer ignore-type */ $target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
Loading history...
It seems like $base_image can also be of type false; however, parameter $src_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

90
            ImageCopyResized($target_image, /** @scrutinizer ignore-type */ $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
Loading history...
91
            ImageDestroy($base_image);
0 ignored issues
show
It seems like $base_image can also be of type false; however, parameter $image of imagedestroy() 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

91
            ImageDestroy(/** @scrutinizer ignore-type */ $base_image);
Loading history...
92
            
93
            return $target_image;
94
        }
95
    }