2

I'm working on a web site which will host thousands of user uploaded images in the formats, .png, .jpeg, and .gif.

Since there will be such a huge amount of images, saving just a few kb of space per file will in the end mean quite a lot on total storage requirements.

My first thought was to enable windows folder compression on the folder that the files are stored in (using a Windows / IIS server). On a total of 1Gb of data the total space saved on this was ~200kb.

This to me seems like a poor result. I therefore went to check if the windows folder compression could be tweaked but according to this post it cant be: NTFS compressed folders

My next though was then that I could use libraries such as Seven Zip Sharp to compress the files individually as I save them. But before I did this I went to test a few different compression programs on a few images.

The results on a 7Mb .gif was that

7z, Compress to .z7 = 1kb space saved  
7z, Compress to .zip = 2kb space INCREASE  
windows, native zip = 4kb space saved.

So this leaves me with two thoughs.. the zipping programs I'm using aren't very good, or images are pretty much already compressed as far as they can be (..and I'm surprised that windows built in compression is better than 7z).

So my question is, is there any way to decrease the filesize of an image archive consisting of the image formats listed above?

Community
  • 1
  • 1
JensB
  • 6,663
  • 2
  • 55
  • 94
  • 2
    You are basically only able to compress extra: path and image headers. Rest (data) is already compressed. Using more advanced compressing technique can compress a bit more, but don't expect anything reasonable. If you would have `bmp` files, then yes, compressed folder will do perfectly. But if you don't care about origianl files content, then converting bmp to jpg/png will then may give you even more than plain `zip`. If you already have jpg/png, then **you can do nothing**. – Sinatr Dec 11 '14 at 13:43

2 Answers2

4

the zipping programs I'm using suck, or images are pretty much already compressed as far as they can be

Most common image formats are already compressed (PNG, JPEG, etc). Compressing a file twice will almost never yield any positive result, most likely it will only increase the file size.

So my question is, is there any way to decrease the filesize of an image archive consisting of the image formats listed above?

No, not likely. Compressed files might have at most a little more to give, but you have specialize on images itself, not the compression algoritm. Some good options are available in the post of Robert Levy. A tool I used to strip out metadata is PNGOUT.

Community
  • 1
  • 1
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • He just needs to use one of those [patented compression algorithms](http://gailly.net/05533051.html) that always result in a smaller file. :) – Dark Falcon Dec 11 '14 at 13:36
  • 3
    @DarkFalcon I have a compression algorithm that can compress any file down to a single bit... my only problem at the moment is with the decompression algorithm :-) – Mark Setchell Dec 12 '14 at 19:17
2

Most users will likely be uploading files that have a basic level of compression already done on them so that's why you aren't seeing a ton of benefit. Some users may be uploading uncompressed files though in which case your attempts would make a difference.

That said, image compression should be thought of as a unique field from normal file compression. Normal file compression techniques will be "lossless", ensuring that every bit of the file is restored when the file is uncompressed - images (and other media) can be compressed in "lossy" ways without degrading the file to an unacceptable level.

There are specialized tools such which you can use to do things like strip out metadata, apply a slight blur, perform sampling, reduce quality, reduce dimensions, etc. Have a look at the answer here for a good example: Recommendation for compressing JPG files with ImageMagick. The top answer took the example file from 264kb to 170kb.

Community
  • 1
  • 1
Robert Levy
  • 28,747
  • 6
  • 62
  • 94
  • Good point. +1. I did think of resizing the image, but that didn't feel like a real solution. The other options are nice though. – Patrick Hofman Dec 11 '14 at 13:54