@@ -48,7 +48,7 @@ class ImageResize
48
48
protected $ source_h ;
49
49
50
50
protected $ source_info ;
51
-
51
+
52
52
protected $ filters = [];
53
53
54
54
/**
@@ -110,23 +110,32 @@ public function __construct($filename)
110
110
}
111
111
112
112
$ finfo = finfo_open (FILEINFO_MIME_TYPE );
113
+ $ checkWebp = false ;
113
114
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
+ }
115
124
}
116
125
117
126
if (!$ image_info = getimagesize ($ filename , $ this ->source_info )) {
118
127
$ image_info = getimagesize ($ filename );
119
128
}
120
129
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
+ }
124
134
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
+ }
130
139
131
140
switch ($ this ->source_type ) {
132
141
case IMAGETYPE_GIF :
@@ -147,10 +156,10 @@ public function __construct($filename)
147
156
break ;
148
157
149
158
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
- }
153
159
$ this ->source_image = imagecreatefromwebp ($ filename );
160
+ $ this ->original_w = imagesx ($ this ->source_image );
161
+ $ this ->original_h = imagesy ($ this ->source_image );
162
+
154
163
break ;
155
164
156
165
default :
@@ -300,7 +309,7 @@ public function save($filename, $image_type = null, $quality = null, $permission
300
309
$ this ->dest_y = 0 ;
301
310
}
302
311
}
303
-
312
+
304
313
imagecopyresampled (
305
314
$ dest_image ,
306
315
$ this ->source_image ,
@@ -313,7 +322,7 @@ public function save($filename, $image_type = null, $quality = null, $permission
313
322
$ this ->source_w ,
314
323
$ this ->source_h
315
324
);
316
-
325
+
317
326
if ($ this ->gamma_correct ) {
318
327
imagegammacorrect ($ dest_image , 1.0 , 2.2 );
319
328
}
0 commit comments