I'm trying to propose storing test result BMP images as PNG, and I've written a Windows CMD file to mass convert tens of GB of BMPs using ImageMagick 6.7.3-2 2011-10-21 Q8. It works great, but I wanted to make sure I can re-create an identical BMP file if it's needed for further processing later. I can convert back to BMP, but an 8MB BMP converts to a 4MB PNG, which converts with ImageMagick to 12MB. Opening the PNG with the GIMP and saving as BMP brings it back to the original BMP's file size. All images compare to 0 different pixels with compare using:
compare -metric AE -fuzz 0
and the only difference between the outputs of identify -verbose on the different size BMPs is the resolution, is tagged in the larger BMP, file size/time stamps and the identify performance metrics.
I've searched around for settings to try, after making sure I was runing a Q8 version, such as adding +matte or -colors 256, or even going through ppm and a second convert to throw away any gamma info which might have been in the PNG. Oddly enough, -colors 256 gives the 12MB file, but -colors 255 gives a 4MB BMP file - half the original's 8MB. identify -verbose states that the 4MB bmp has a depth of 4/8-bit, Gray: 8-bit, but Colormap: 16, and only 16 colors are listed in the map.
The 12MB files are probably fine to use, but I'd like to understand what's going on, and be able to reproduce the original file size if possible, since this whole project was to save server disk space. Anyone?
BMP -> PNG -> BMP adds 50% to file size?!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: BMP -> PNG -> BMP adds 50% to file size?!
I don't believe I can help much as I know little about BMP, but you find what you need at http://www.imagemagick.org/Usage/formats/#bmp
Re: BMP -> PNG -> BMP adds 50% to file size?!
Thanks for the really quick reply. Unfortunately, that's one of the pages I'd already found and where I got the suggestions to try +matte and piping through PPM format...
Re: BMP -> PNG -> BMP adds 50% to file size?!
I thought I had - I know I had tried BMP3 with no difference I could tell, but BMP2 did the trick - brought the PNG back to a BMP the same size as the original. BMP3 and 4 must include extra info per pixel, even in Q8 versions. Thanks, fmw42, for prompting me to be that much more thorough in trying every option, it's just what I needed!
So, in case an example would help anyone else, I had been using:
The "4" in "-quality 94" specifies a filter which imperically gave me the best compression on the BMP images I'm working with, YMMV based on your images of course.
My batch file then programatically checks to make sure the resulting image was identical:
and if the error level was 0 (found 0 pixels different), I'd delete the %BMP% file.
Now, I've got the return convert working as:
(I had also found a snippit of Perl code which copied the time-stamp from one file to another at http://www.rocketaware.com/perl/perlfaq ... stamp_.htm, and include a call to that in my batch file, but that's a bit off topic for an ImageMagick forum, as is the Windows "FOR /F" loop syntax I found at http://ss64.com/nt/for_cmd.html)
So, in case an example would help anyone else, I had been using:
Code: Select all
convert -quality 94 %BMP% %PNG%
My batch file then programatically checks to make sure the resulting image was identical:
Code: Select all
compare -metric AE -fuzz 0 %BMP% %PNG% miff: 2>&1 1> nul | grep -q "^0$"
Now, I've got the return convert working as:
Code: Select all
convert %PNG% bmp2:%BMP%
Re: BMP -> PNG -> BMP adds 50% to file size?!
The -quality 94 shouldn't have any effect on the size of the BMP,
only on the size of the intermediate PNG. If you wouldn't mind sharing
one of your images that exhibits this behavior, please post a link
or mail it directly to me: glennrp at gmail.com
only on the size of the intermediate PNG. If you wouldn't mind sharing
one of your images that exhibits this behavior, please post a link
or mail it directly to me: glennrp at gmail.com
Re: BMP -> PNG -> BMP adds 50% to file size?!
Looking at the output of
BMP3 encoder uses BI_RLE8 compression while the BMP2
encoder uses BI_RGB.
larger because of the bigger BMP3 header but otherwise
fine).
- convert 00min.png -debug coder default.bmp
- convert 00min.png -debug coder bmp2:bmp2.bmp
BMP3 encoder uses BI_RLE8 compression while the BMP2
encoder uses BI_RGB.
- convert 00min.png -compress none none.bmp
larger because of the bigger BMP3 header but otherwise
fine).