@@ -108,23 +108,37 @@ public function __construct($filename)
108
108
}
109
109
110
110
$ finfo = finfo_open (FILEINFO_MIME_TYPE );
111
+ $ checkWebp = false ;
112
+ if (strstr (finfo_file ($ finfo , $ filename ), 'image ' ) === false ) {
113
+ if (version_compare (PHP_VERSION , '7.0.0 ' , '<= ' ) && strstr (file_get_contents ($ filename ), 'WEBPVP8 ' ) !== false ) {
114
+ $ checkWebp = true ;
115
+ $ this ->source_type = IMAGETYPE_WEBP ;
116
+ } else {
117
+ throw new ImageResizeException ('Unsupported file type ' );
118
+ }
119
+ } elseif (strstr (finfo_file ($ finfo , $ filename ), 'image/webp ' ) !== false ) {
120
+ $ checkWebp = true ;
121
+ $ this ->source_type = IMAGETYPE_WEBP ;
122
+ }
111
123
112
124
if (!$ image_info = getimagesize ($ filename , $ this ->source_info )) {
113
125
$ image_info = getimagesize ($ filename );
114
126
}
115
127
116
- if (!$ image_info ) {
117
- if (strstr (finfo_file ($ finfo , $ filename ), 'image ' ) !== false ) {
118
- throw new ImageResizeException ('Unsupported image type ' );
128
+ if (!$ checkWebp ) {
129
+ if (!$ image_info ) {
130
+ if (strstr (finfo_file ($ finfo , $ filename ), 'image ' ) !== false ) {
131
+ throw new ImageResizeException ('Unsupported image type ' );
132
+ }
133
+
134
+ throw new ImageResizeException ('Could not read file ' );
119
135
}
120
136
121
- throw new ImageResizeException ('Could not read file ' );
137
+ $ this ->original_w = $ image_info [0 ];
138
+ $ this ->original_h = $ image_info [1 ];
139
+ $ this ->source_type = $ image_info [2 ];
122
140
}
123
141
124
- $ this ->original_w = $ image_info [0 ];
125
- $ this ->original_h = $ image_info [1 ];
126
- $ this ->source_type = $ image_info [2 ];
127
-
128
142
switch ($ this ->source_type ) {
129
143
case IMAGETYPE_GIF :
130
144
$ this ->source_image = imagecreatefromgif ($ filename );
@@ -152,12 +166,12 @@ public function __construct($filename)
152
166
153
167
case IMAGETYPE_AVIF :
154
168
$ this ->source_image = imagecreatefromavif ($ filename );
155
- $ this ->original_w = imagesx ($ this ->source_image );
156
- $ this ->original_h = imagesy ($ this ->source_image );
157
-
158
169
break ;
159
170
160
171
case IMAGETYPE_BMP :
172
+ if (version_compare (PHP_VERSION , '7.2.0 ' , '< ' )) {
173
+ throw new ImageResizeException ('For bmp support PHP >= 7.2.0 is required ' );
174
+ }
161
175
$ this ->source_image = imagecreatefrombmp ($ filename );
162
176
break ;
163
177
0 commit comments