Reducing a file's size

Started by
6 comments, last by smart_idiot 19 years, 6 months ago
Hi, I am trying to take an image file and reduce its size in bytes to maximum amount possible. I tried stripping all unecessary info out and only saving the info like width, height, data. But when I did this to a GIF it increased to 47 kb while the filesize is 32kb on disk. However with a BMP I could get it down to 4kb from 192 kb. So is there something I am doing wrong ? I am even converting the width and height to char to save some bytes. Thanks
The more applications I write, more I find out how less I know
Advertisement
Use PNG.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
That neither answers my question nor solves the purpose.
The more applications I write, more I find out how less I know
Quote:Original post by CRACK123
That neither answers my question nor solves the purpose.


If your question is not about compressing size of file and purpose isn't saving space, then you'll have to explain it cleaner.

Oxyd
While his answer itself might not have been the solution you wanted, the general idea of his post is the best advice you can get.

Make the filesize smaller by using a format that is smaller. i.e. one that holds only as much detail as you need (8bpp instead of 24bpp perhaps) or is perhaps compressed. Finding the right algorythm makes a much bigger difference than cutting a couple bytes out of a file.

And when you get to as small as you are getting, you'll see a pretty good benefit by combining all your small files into one big resource file so you aren't wasting a bunch of space due to the allocation size of the filesystem.
Shoot Pixels Not People
GIF is already packed while BMP isn't. So using a packer may actually grow the file size of gif. I think the standard packers like pkzip will notice that and leave the file unpacked.
The gif will be larger because the original was compressed (it uses LZW I believe) and the tools you are using either do not write compressed gif's or were not set up to do so.

Are you trying to achieve lossless compression btw?
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
You want to reduce the size of an image. If you want to compress it, you're out of luck - all the useful image formats are already compressed. Their data contains virtually no patterns that a file compresser could take advantage of. Your only hope is to use a better file format in the first place. So, to restate my original advice:

Use PNG. (or, if you don't need a perfect 1:1 copy, use jpeg)

And if that wasn't what you were asking, then you did a terrible job of conveying your problem.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.

This topic is closed to new replies.

Advertisement