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 $moveToAttribute; |
||
39 | |||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | private $excludeAttributesList; |
||
44 | |||
45 | /** |
||
46 | * constructor - set root directory to relative url |
||
47 | * |
||
48 | * @param string $rootpath |
||
49 | * @param int $type |
||
50 | * @param string $moveToAttribute |
||
51 | * @param array $excludeAttributesList |
||
52 | */ |
||
53 | public function __construct( |
||
64 | |||
65 | |||
66 | private function gcd($a,$b) { |
||
69 | |||
70 | /** |
||
71 | * create lossy gif image and encode to data uri format |
||
72 | * minimal size is jpeg |
||
73 | * |
||
74 | * @param $src resource GD library |
||
75 | * @param int $minwidth min width in pixels (height autocalculte) |
||
76 | * |
||
77 | * @return string data uri format |
||
78 | */ |
||
79 | public function getLossyGifDataURI($src, $minwidth = 75) |
||
96 | |||
97 | /** |
||
98 | * create blank image with same size in data uri format |
||
99 | * minimal size is gif |
||
100 | * |
||
101 | * @param $src |
||
102 | * @param int $red red component background color (default 255) |
||
103 | * @param int $green green component background color (default 255) |
||
104 | * @param int $blue blue component background color (default 255) |
||
105 | * |
||
106 | * @return string data uri format |
||
107 | */ |
||
108 | public function getMinGifDataURI($src, $red = 255, $green = 255, $blue = 255) |
||
134 | |||
135 | |||
136 | /** |
||
137 | * find type of image and open it |
||
138 | * |
||
139 | * @param string $file |
||
140 | * |
||
141 | * @return bool|resource |
||
142 | */ |
||
143 | private function openImage($file) |
||
167 | |||
168 | /** |
||
169 | * replace all src attributes from img tags with datauri and set another attribute with old src value |
||
170 | * support jpeg, png or gif file format |
||
171 | * |
||
172 | * @param string $html |
||
173 | * |
||
174 | * @throws \Exception |
||
175 | * @return string |
||
176 | */ |
||
177 | public function autoDataURI($html) |
||
211 | } |
||
212 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: