0

I havent decided on a technology yet but i wanted to ask. BMP images are large, i compressed a 3mb image to 50k. Browsers can decode gzip text, so would it be possible to gzip bmp on my server and have the user request mysite.com/images/test.bmp and have it decompress my gzip bmp on the other side so the user doesnt notice a difference?

1
  • Why do you want to use BMP images on the server, instead of a more modern format like PNG? May 31, 2009 at 9:52

6 Answers 6

6

If possible, use PNG as image format. It's the defacto standard for lossless image compression and will probably surpass the compression level achieved by merely gziping bitmaps.

If you need to use BMP because of dependencies from legacy systems, you can try using the output compression methods available in your webserver, e.g. see mod_deflate for Apache. Wireshark can be especially helpful in testing/debugging such setups.

3

Gzip before sending. Good webservers (Apache, NGINX, and probably lighttpd) all support having a 'image.bmp.gz' on disk, and sending that instead of 'image.bmp' if the browser supports it. Add this to .htaccess in apache: "AddEncoding x-gzip .gz". I fraggin' hate it when people think compressing files on the fly really saves anything.

Really, you should just use PNGs, since they are gzipped BMPs, sometimes with an alpha channel thrown in as well. The format was created to make people stop using GIFs, who's compression algorithm was, and might still be under patent by Unisys. Oh, and a bmp.gz and png will compress equally well.

2
  • +1. I cant use PNG i have to have the original file available (IE the user must get a BMP back if he wants instead of a png). On upload i compress bmp bc i know it will compress well. I just didnt know how to allow /files/image.bitmap to use the .gz version on server. Thanks for your answer.
    – user274
    Aug 10, 2009 at 22:17
  • "I fraggin' hate it when people think compressing files on the fly really saves anything." -- I believe the UX improvement of an airplane user downloading a 30 KB bitmap image instead of 8 MB is worth the extra 0.1 milliseconds of processing time for the server. Note also that PNG are not "gzipped BMPs" -- the format includes many features beyond pixel data and uses LZW while gzip is based on DEFLATE.
    – AndrewF
    Sep 13, 2019 at 1:45
2

With using apache and mod_gzip or mod_deflate, if the client accepts gzipped content, apache will serve gzipped file. Even you can add a file.gz in pair with the original file helping out apache with gzipping.

If you do not want to host original files, normally apache will answer with 404 for a .bmp request. (You do not have that file do you?). But with the help of apache mod_rewrite you can add some rewrite rules to serve gzipped bmp instead of returning a 404 Error.

Sample (and untested) rewrite rules:

RewriteEngine On
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule ^(.*).bmp$ $1.bmp.gz 
0

I am not sure if my test is representative: I compressed a local bmp file with gzip and tried to open it on Mac OS X with Safari and Firefox: it does not work (with or without .gz extension).

3
  • HTTP has gzip compression on transport level. Browsers don't emulate that with file:// protocol.
    – Kornel
    May 30, 2009 at 23:46
  • Does it mean that the file transmited on the network is uncompressed? The benefit would then be only on server storage space.
    – mouviciel
    May 31, 2009 at 8:46
  • No it does mean that the file is stored uncompressed on the server and will be compressed by the server just before transmission, the browser will then decompress it just before showing it (or rather downloading in case of BMP) Jun 12, 2009 at 7:12
0

From mod_gzip's sourceforge.net page:

"mod_gzip is an Internet Content Acceleration module for the popular Apache Web Server. It compresses the contents delivered to the client. There is no need to install any additional software on the client!"

I think it basically compresses everything it sends with the exception of anything which is already compressed, such as JPGs or GIFs, etc. I think it is often enabled in default Apache installations, but you can Google for docs.

0

Hmm, interestingly ziproxy http://ziproxy.sourceforge.net/ seems to gzip "text likes" and convert images to jpeg.

I can see possible issues zipping bmps - might not compress well, or fast, for example. Certainly conversion to a.n.other format is more browser-compatible. As suggested, PNG will support everything you need, jpeg might do if you can hack lossy compression in your application.

Don't quote me on this but i am fairly sure you could automate this and convert on-the-fly. I would be inclined to run a (nightly?) job that converts bmps (use "convert" if you're on unix) and rewrites links.

Give us a bit more "why" and we may get a better "how" :)

Where are your bmps coming from, how are they being serverd, what platform, etc.?

You must log in to answer this question.