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 int |
||
37 | */ |
||
38 | private $type; |
||
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 image and encode to data uri format |
||
78 | * minimal size is jpeg |
||
79 | * |
||
80 | * @param $src resource GD library |
||
81 | * @param int $quality jpeg quality from 0 (poor quality) to 100 (best quality) - default 0 |
||
82 | * @param bool $minsize rescale to min size (default true) |
||
83 | * @return string |
||
84 | */ |
||
85 | public function getLossyDataURI($src, $quality = 0, $minsize = true) |
||
113 | |||
114 | /** |
||
115 | * create blank image with same size in data uri format |
||
116 | * minimal size is gif |
||
117 | * |
||
118 | * @param $src resource GD library |
||
119 | * @param int $red red component background color (default 255) |
||
120 | * @param int $green green component background color (default 255) |
||
121 | * @param int $blue blue component background color (default 255) |
||
122 | * @param bool $minsize rescale to min size (default true) |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | public function getBlankDataURI($src, $red = 255, $green = 255, $blue = 255, $minsize = true) |
||
154 | |||
155 | |||
156 | /** |
||
157 | * find type of image and open it |
||
158 | * |
||
159 | * @param string $file |
||
160 | * |
||
161 | * @return bool|resource |
||
162 | */ |
||
163 | private function openImage($file) |
||
187 | |||
188 | /** |
||
189 | * replace all src attributes from img tags with datauri and set another attribute with old src value |
||
190 | * support jpeg, png or gif file format |
||
191 | * |
||
192 | * @param string $html |
||
193 | * @param bool $minsize rescale to minsize (default true) |
||
194 | * |
||
195 | * @throws \Exception |
||
196 | * @return string |
||
197 | */ |
||
198 | public function autoDataURI($html, $minsize=true) |
||
235 | |||
236 | /** |
||
237 | * @param string $html |
||
238 | * |
||
239 | * @throws \Exception |
||
240 | * @return string |
||
241 | */ |
||
242 | public function autoWidthHeight($html) |
||
265 | } |
||
266 |