@@ -105,6 +105,11 @@ public function __construct($filename)
105
105
if (!defined ('IMAGETYPE_WEBP ' )) {
106
106
define ('IMAGETYPE_WEBP ' , 18 );
107
107
}
108
+
109
+ if (!defined ('IMAGETYPE_BMP ' )) {
110
+ define ('IMAGETYPE_BMP ' , 6 );
111
+ }
112
+
108
113
if ($ filename === null || empty ($ filename ) || (substr ($ filename , 0 , 5 ) !== 'data: ' && !is_file ($ filename ))) {
109
114
throw new ImageResizeException ('File does not exist ' );
110
115
}
@@ -129,6 +134,10 @@ public function __construct($filename)
129
134
130
135
if (!$ checkWebp ) {
131
136
if (!$ image_info ) {
137
+ if (strstr (finfo_file ($ finfo , $ filename ), 'image ' ) !== false ) {
138
+ throw new ImageResizeException ('Unsupported image type ' );
139
+ }
140
+
132
141
throw new ImageResizeException ('Could not read file ' );
133
142
}
134
143
@@ -162,6 +171,13 @@ public function __construct($filename)
162
171
163
172
break ;
164
173
174
+ case IMAGETYPE_BMP :
175
+ if (version_compare (PHP_VERSION , '7.2.0 ' , '< ' )) {
176
+ throw new ImageResizeException ('For bmp support PHP >= 7.2.0 is required ' );
177
+ }
178
+ $ this ->source_image = imagecreatefrombmp ($ filename );
179
+ break ;
180
+
165
181
default :
166
182
throw new ImageResizeException ('Unsupported image type ' );
167
183
}
@@ -170,6 +186,8 @@ public function __construct($filename)
170
186
throw new ImageResizeException ('Could not load image ' );
171
187
}
172
188
189
+ finfo_close ($ finfo );
190
+
173
191
return $ this ->resize ($ this ->getSourceWidth (), $ this ->getSourceHeight ());
174
192
}
175
193
@@ -291,6 +309,22 @@ public function save($filename, $image_type = null, $quality = null, $permission
291
309
imagecolortransparent ($ dest_image , $ background );
292
310
imagefill ($ dest_image , 0 , 0 , $ background );
293
311
break ;
312
+
313
+ case IMAGETYPE_BMP :
314
+ if (version_compare (PHP_VERSION , '7.2.0 ' , '< ' )) {
315
+ throw new ImageResizeException ('For WebP support PHP >= 7.2.0 is required ' );
316
+ }
317
+
318
+ if (!empty ($ exact_size ) && is_array ($ exact_size )) {
319
+ $ dest_image = imagecreatetruecolor ($ exact_size [0 ], $ exact_size [1 ]);
320
+ $ background = imagecolorallocate ($ dest_image , 255 , 255 , 255 );
321
+ imagefilledrectangle ($ dest_image , 0 , 0 , $ exact_size [0 ], $ exact_size [1 ], $ background );
322
+ } else {
323
+ $ dest_image = imagecreatetruecolor ($ this ->getDestWidth (), $ this ->getDestHeight ());
324
+ $ background = imagecolorallocate ($ dest_image , 255 , 255 , 255 );
325
+ imagefilledrectangle ($ dest_image , 0 , 0 , $ this ->getDestWidth (), $ this ->getDestHeight (), $ background );
326
+ }
327
+ break ;
294
328
}
295
329
296
330
imageinterlace ($ dest_image , $ this ->interlace );
@@ -361,6 +395,10 @@ public function save($filename, $image_type = null, $quality = null, $permission
361
395
362
396
imagepng ($ dest_image , $ filename , $ quality );
363
397
break ;
398
+
399
+ case IMAGETYPE_BMP :
400
+ imagebmp ($ dest_image , $ filename , $ quality );
401
+ break ;
364
402
}
365
403
366
404
if ($ permissions ) {
0 commit comments