@@ -105,6 +105,11 @@ public function __construct($filename)
105105 if (!defined ('IMAGETYPE_WEBP ' )) {
106106 define ('IMAGETYPE_WEBP ' , 18 );
107107 }
108+
109+ if (!defined ('IMAGETYPE_BMP ' )) {
110+ define ('IMAGETYPE_BMP ' , 6 );
111+ }
112+
108113 if ($ filename === null || empty ($ filename ) || (substr ($ filename , 0 , 5 ) !== 'data: ' && !is_file ($ filename ))) {
109114 throw new ImageResizeException ('File does not exist ' );
110115 }
@@ -129,6 +134,10 @@ public function __construct($filename)
129134
130135 if (!$ checkWebp ) {
131136 if (!$ image_info ) {
137+ if (strstr (finfo_file ($ finfo , $ filename ), 'image ' ) !== false ) {
138+ throw new ImageResizeException ('Unsupported image type ' );
139+ }
140+
132141 throw new ImageResizeException ('Could not read file ' );
133142 }
134143
@@ -162,6 +171,13 @@ public function __construct($filename)
162171
163172 break ;
164173
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+
165181 default :
166182 throw new ImageResizeException ('Unsupported image type ' );
167183 }
@@ -170,6 +186,8 @@ public function __construct($filename)
170186 throw new ImageResizeException ('Could not load image ' );
171187 }
172188
189+ finfo_close ($ finfo );
190+
173191 return $ this ->resize ($ this ->getSourceWidth (), $ this ->getSourceHeight ());
174192 }
175193
@@ -291,6 +309,22 @@ public function save($filename, $image_type = null, $quality = null, $permission
291309 imagecolortransparent ($ dest_image , $ background );
292310 imagefill ($ dest_image , 0 , 0 , $ background );
293311 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 ;
294328 }
295329
296330 imageinterlace ($ dest_image , $ this ->interlace );
@@ -361,6 +395,10 @@ public function save($filename, $image_type = null, $quality = null, $permission
361395
362396 imagepng ($ dest_image , $ filename , $ quality );
363397 break ;
398+
399+ case IMAGETYPE_BMP :
400+ imagebmp ($ dest_image , $ filename , $ quality );
401+ break ;
364402 }
365403
366404 if ($ permissions ) {
0 commit comments