@@ -48,7 +48,7 @@ class ImageResize
4848 protected $ source_h ;
4949
5050 protected $ source_info ;
51-
51+ 5252 protected $ filters = [];
5353
5454 /**
@@ -110,23 +110,32 @@ public function __construct($filename)
110110 }
111111
112112 $ finfo = finfo_open (FILEINFO_MIME_TYPE );
113+ $ checkWebp = false ;
113114 if (strstr (finfo_file ($ finfo , $ filename ), 'image ' ) === false ) {
114- throw new ImageResizeException ('Unsupported file type ' );
115+ if (version_compare (PHP_VERSION , '5.6.0 ' , '<= ' )) {
116+ if (strstr (file_get_contents ($ filename ), 'WEBPVP8 ' ) !== false ) {
117+ $ checkWebp = true ;
118+ $ this ->source_type = IMAGETYPE_WEBP ;
119+ }
120+ 121+ } else {
122+ throw new ImageResizeException ('Unsupported file type ' );
123+ }
115124 }
116125
117126 if (!$ image_info = getimagesize ($ filename , $ this ->source_info )) {
118127 $ image_info = getimagesize ($ filename );
119128 }
120129
121- if (!$ image_info ) {
122- throw new ImageResizeException ('Could not read file ' );
123- }
130+ if (!$ checkWebp ) {
131+ if (!$ image_info ) {
132+ throw new ImageResizeException ('Could not read file ' );
133+ }
124134
125- list (
126- $ this ->original_w ,
127- $ this ->original_h ,
128- $ this ->source_type
129- ) = $ image_info ;
135+ $ this ->original_w = $ image_info [0 ];
136+ $ this ->original_h = $ image_info [1 ];
137+ $ this ->source_type = $ image_info [2 ];
138+ }
130139
131140 switch ($ this ->source_type ) {
132141 case IMAGETYPE_GIF :
@@ -147,10 +156,10 @@ public function __construct($filename)
147156 break ;
148157
149158 case IMAGETYPE_WEBP :
150- if (version_compare (PHP_VERSION , '5.5.0 ' , '< ' )) {
151- throw new ImageResizeException ('For WebP support PHP >= 5.5.0 is required ' );
152- }
153159 $ this ->source_image = imagecreatefromwebp ($ filename );
160+ $ this ->original_w = imagesx ($ this ->source_image );
161+ $ this ->original_h = imagesy ($ this ->source_image );
162+ 154163 break ;
155164
156165 default :
@@ -300,7 +309,7 @@ public function save($filename, $image_type = null, $quality = null, $permission
300309 $ this ->dest_y = 0 ;
301310 }
302311 }
303-
312+ 304313 imagecopyresampled (
305314 $ dest_image ,
306315 $ this ->source_image ,
@@ -313,7 +322,7 @@ public function save($filename, $image_type = null, $quality = null, $permission
313322 $ this ->source_w ,
314323 $ this ->source_h
315324 );
316-
325+ 317326 if ($ this ->gamma_correct ) {
318327 imagegammacorrect ($ dest_image , 1.0 , 2.2 );
319328 }
0 commit comments