1 | <?php |
||
25 | class GlLazyLoadImg |
||
26 | { |
||
27 | const BLANK = 0; |
||
28 | const LOSSY = 1; |
||
29 | |||
30 | /** |
||
31 | * @var string rootpath |
||
32 | */ |
||
33 | private $rootpath; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | private $datauri; |
||
|
|||
39 | |||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private $moveToAttribute; |
||
45 | |||
46 | /** |
||
47 | * @var array |
||
48 | */ |
||
49 | private $excludeAttributesList; |
||
50 | |||
51 | /** |
||
52 | * constructor - set root directory to relative url |
||
53 | * |
||
54 | * @param string $rootpath |
||
55 | * @param int $type |
||
56 | * @param string $moveToAttribute |
||
57 | * @param array $excludeAttributesList |
||
58 | */ |
||
59 | public function __construct( |
||
70 | |||
71 | |||
72 | private function gcd($a,$b) { |
||
75 | |||
76 | /** |
||
77 | * create lossy gif image and encode to data uri format |
||
78 | * minimal size is jpeg |
||
79 | * |
||
80 | * @param $src resource GD library |
||
81 | * @param int $minwidth min width in pixels (height autocalculte) |
||
82 | * |
||
83 | * @return string data uri format |
||
84 | */ |
||
85 | public function getLossyGifDataURI($src, $minwidth = 75) |
||
86 | { |
||
87 | $src = imagescale($src, $minwidth, -1, IMG_NEAREST_NEIGHBOUR); |
||
88 | |||
89 | ob_start(); |
||
90 | imagegif($src); |
||
91 | $data = ob_get_contents(); |
||
92 | ob_end_clean(); |
||
93 | |||
94 | imagedestroy($src); |
||
95 | |||
96 | $base64 = base64_encode($data); |
||
97 | |||
98 | $mime = 'image/gif'; |
||
99 | |||
100 | return ('data:' . $mime . ';base64,' . $base64); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * create blank image with same size in data uri format |
||
105 | * minimal size is gif |
||
106 | * |
||
107 | * @param int $red red component background color (default 255) |
||
108 | * @param int $green green component background color (default 255) |
||
109 | * @param int $blue blue component background color (default 255) |
||
110 | * |
||
111 | * @return string data uri format |
||
112 | */ |
||
113 | public function getMinGifDataURI($src, $red = 255, $green = 255, $blue = 255, $minsize = true) |
||
114 | { |
||
115 | $width = imagesx($src); |
||
116 | $height = imagesy($src); |
||
117 | |||
118 | $gcd = $this->gcd($width, $height); |
||
119 | $width = $width / $gcd; |
||
120 | $height = $height / $gcd; |
||
121 | |||
122 | $img = imagecreatetruecolor($width, $height); |
||
123 | $bgcol = imagecolorallocate($img, $red, $green, $blue); |
||
124 | imageFill($img, 0, 0, $bgcol); |
||
125 | |||
126 | ob_start(); |
||
127 | imagegif($img); |
||
128 | $data = ob_get_contents(); |
||
129 | ob_end_clean(); |
||
130 | |||
131 | $base64 = base64_encode($data); |
||
132 | |||
133 | imagedestroy($img); |
||
134 | |||
135 | $mime = 'image/gif'; |
||
136 | |||
137 | return ('data:' . $mime . ';base64,' . $base64); |
||
138 | } |
||
139 | |||
140 | |||
141 | /** |
||
142 | * find type of image and open it |
||
143 | * |
||
144 | * @param string $file |
||
145 | * |
||
146 | * @return bool|resource |
||
147 | */ |
||
148 | private function openImage($file) |
||
172 | |||
173 | /** |
||
174 | * replace all src attributes from img tags with datauri and set another attribute with old src value |
||
175 | * support jpeg, png or gif file format |
||
176 | * |
||
177 | * @param string $html |
||
178 | * |
||
179 | * @throws \Exception |
||
180 | * @return string |
||
181 | */ |
||
182 | public function autoDataURI($html) |
||
216 | } |
||
217 |
This check marks private properties in classes that are never used. Those properties can be removed.