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 $minwidth min width in pixels (height autocalculte) |
||
82 | * |
||
83 | * @return string data uri format |
||
84 | */ |
||
85 | public function getLossyDataURI($src, $minwidth = 75) |
||
102 | |||
103 | /** |
||
104 | * create blank image with same size in data uri format |
||
105 | * minimal size is gif |
||
106 | * |
||
107 | * @param $src resource GD library |
||
108 | * @param int $red red component background color (default 255) |
||
109 | * @param int $green green component background color (default 255) |
||
110 | * @param int $blue blue component background color (default 255) |
||
111 | * @param bool $minsize rescale to min size (default true) |
||
112 | * |
||
113 | * @return string data uri format |
||
114 | */ |
||
115 | public function getBlankDataURI($src, $red = 255, $green = 255, $blue = 255, $minsize = true) |
||
143 | |||
144 | |||
145 | /** |
||
146 | * find type of image and open it |
||
147 | * |
||
148 | * @param string $file |
||
149 | * |
||
150 | * @return bool|resource |
||
151 | */ |
||
152 | private function openImage($file) |
||
176 | |||
177 | /** |
||
178 | * replace all src attributes from img tags with datauri and set another attribute with old src value |
||
179 | * support jpeg, png or gif file format |
||
180 | * |
||
181 | * @param string $html |
||
182 | * @param bool $minsize rescale to minsize (default true) |
||
183 | * |
||
184 | * @throws \Exception |
||
185 | * @return string |
||
186 | */ |
||
187 | public function autoDataURI($html, $minsize=true) |
||
224 | |||
225 | /** |
||
226 | * @param string $html |
||
227 | * |
||
228 | * @throws \Exception |
||
229 | * @return string |
||
230 | */ |
||
231 | public function autoWidthHeight($html) |
||
254 | } |
||
255 |