@@ -47,6 +47,8 @@ public function __construct($contents)
47
47
if (!$ this ->isExtendedFormat ()) {
48
48
// throw new \Exception('Only extended WebP format is supported');
49
49
}
50
+
51
+ $ this ->setSizeFromString ($ contents );
50
52
}
51
53
52
54
/**
@@ -144,20 +146,12 @@ public function getIptc()
144
146
*/
145
147
public static function fromFile ($ filename )
146
148
{
147
- $ imageSize = getimagesize ($ filename );
148
- if ($ imageSize === false ) {
149
- throw new \Exception (sprintf ('Could not get image size for %s ' , $ filename ));
149
+ $ contents = file_get_contents ($ filename );
150
+ if ($ contents === false ) {
151
+ throw new \Exception (sprintf ('Could not open file %s ' , $ filename ));
150
152
}
151
153
152
- $ width = $ imageSize [0 ];
153
- $ height = $ imageSize [1 ];
154
-
155
- $ webp = new self (file_get_contents ($ filename ));
156
-
157
- $ webp ->width = $ width ;
158
- $ webp ->height = $ height ;
159
-
160
- return $ webp ;
154
+ return new self ($ contents );
161
155
}
162
156
163
157
@@ -168,20 +162,7 @@ public static function fromFile($filename)
168
162
*/
169
163
public static function fromString ($ string )
170
164
{
171
- $ imageSize = getimagesizefromstring ($ string );
172
- if ($ imageSize === false ) {
173
- throw new \Exception ('Invalid WebP data ' );
174
- }
175
-
176
- $ width = $ imageSize [0 ];
177
- $ height = $ imageSize [1 ];
178
-
179
- $ webp = new self ($ string );
180
-
181
- $ webp ->width = $ width ;
182
- $ webp ->height = $ height ;
183
-
184
- return $ webp ;
165
+ return new self ($ string );
185
166
}
186
167
187
168
/**
0 commit comments