Reducing the file size of a very large images, without changing the image dimensions

后端 未结 12 2270
囚心锁ツ
囚心锁ツ 2021-01-31 08:51

Consider an application handling uploading of potentially very large PNG files.

All uploaded files must be stored to disk for later retrieval. However, the PNG files ca

12条回答
  •  不要未来只要你来
    2021-01-31 08:56

    Your example is troublesome because a 30MB image at 800x600 resolution is storing 500 bits per pixel. Clearly wildly unrealistic. Please give us real numbers.

    Meanwhile, the "cheap and cheerful" approach I would try would be as follows: scale the image down by a factor of 6, then scale it back up by a factor of 6, then run it through PNG compression. If you get lucky, you'll reduce image size by a factor of 36. If you get unlucky the savings will be more like 6.

    pngtopng big.png | pnmscale -reduce 6 | pnmscale 6 | pnmtopng > big.png
    

    If that's not enough you can toss a ppmquant in the middle (on the small image) to reduce the number of colors. (The examples are netpbm/pbmplus, which I have always found easier to understand than ImageMagick.)

    To know whether such a solution is reasonable, we have to know the true numbers of your problem.

    Also, if you are really going to throw away the information permanently, you are almost certainly better off using JPEG compression, which is designed to lose information reasonably gracefully. Is there some reason JPEG is not appropriate for your application?

提交回复
热议问题