Basic   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 123
ccs 40
cts 40
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getHeight() 0 4 1
A getHeightBytes() 0 4 1
A getWidth() 0 4 1
A getWidthBytes() 0 4 1
A getDimImage() 0 8 2
A isGdSupported() 0 4 1
A isGdLoaded() 0 5 1
A identifyImg() 0 24 1
1
<?php
2
3
namespace Posprint\Graphics;
4
5
/**
6
 * Basic method for graphics classes
7
 *
8
 * @codeCoverageIgnore
9
 * @category  NFePHP
10
 * @package   Posprint
11
 * @copyright Copyright (c) 2016
12
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
13
 * @author    Roberto L. Machado <linux dot rlm at gmail dot com>
14
 * @link      http://github.com/nfephp-org/posprint for the canonical source repository
15
 */
16
17
abstract class Basic
18
{
19
    const LOW = 'low';
20
    const MEDIUM = 'medium';
21
    const QUARTILE = 'quartile';
22
    const HIGH = 'high';
23
    
24
    /**
25
     * Image GD
26
     *
27
     * @var resource
28
     */
29
    public $img;
30
    /**
31
     * Image Height
32
     *
33
     * @var int
34
     */
35
    protected $imgHeight = 0;
36
    /**
37
     * Image Width
38
     *
39
     * @var int
40
     */
41 2
    protected $imgWidth = 0;
42
    
43 2
    /**
44
     * @return int height of the image in pixels
45
     */
46
    public function getHeight()
47
    {
48
        return $this->imgHeight;
49 1
    }
50
    
51 1
    /**
52
     * @return int Number of bytes to represent a row of this image
53
     */
54
    public function getHeightBytes()
55
    {
56
        return (int)(($this->imgHeight + 7) / 8);
57 1
    }
58
    
59 1
    /**
60
     * @return int Width of the image
61
     */
62
    public function getWidth()
63
    {
64
        return $this->imgWidth;
65 1
    }
66
    
67 1
    /**
68
     * @return int Number of bytes to represent a row of this image
69
     */
70
    public function getWidthBytes()
71
    {
72
        return (int)(($this->imgWidth + 7) / 8);
73
    }
74
    
75
    /**
76
     * getDimImage
77 9
     * Get width and height of resource image
78
     * and save in properties
79 9
     *
80 8
     * @return array with dimentions of image
81 8
     */
82 8
    public function getDimImage()
83 9
    {
84
        if (is_resource($this->img)) {
85
            $this->imgHeight = imagesy($this->img);
86
            $this->imgWidth = imagesx($this->img);
87
        }
88
        return ['height'  => $this->imgHeight, 'width' => $this->imgWidth];
89 12
    }
90
    
91 12
    /**
92
     * @return boolean True if GD is supported, false otherwise (a wrapper for the version, for mocking in tests)
93
     */
94
    protected function isGdSupported()
95
    {
96
        return $this->isGdLoaded();
97 12
    }
98
99 12
    /**
100 12
     * @return boolean True if GD is loaded, false otherwise
101
     */
102
    protected function isGdLoaded()
103
    {
104
        $gdImgProcessing = extension_loaded('gd');
105
        return $gdImgProcessing;
106
    }
107
    
108
    /**
109
     * identifyImg
110 8
     * Identifies image file type
111
     *
112 8
     * @param  string $filename
113
     * @return string
114 8
     */
115 8
    protected function identifyImg($filename)
116 8
    {
117 8
        $imgtype = exif_imagetype($filename);
118 8
        $aImgTypes = [
119 8
            0 => 'NULL',
120 8
            1 => 'GIF',
121 8
            2 => 'JPEG',
122 8
            3 => 'PNG',
123 8
            4 => 'SWF',
124 8
            5 => 'PSD',
125 8
            6 => 'BMP',
126 8
            7 => 'TIFF_II',
127 8
            8 => 'TIFF_MM',
128 8
            9 => 'JPC',
129 8
            10 => 'JP2',
130 8
            11 => 'JPX',
131 8
            12 => 'JB2',
132 8
            13 => 'SWC',
133
            14 => 'IFF',
134
            15 => 'WBMP',
135
            16 => 'XBM',
136
            17 => 'ICO'];
137
        return $aImgTypes[$imgtype];
138
    }
139
}
140