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

后端 未结 12 2127
囚心锁ツ
囚心锁ツ 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 09:03

    It depends a lot on what you want at the end, I often like to reduce the number of colors while perserving the size. In many many cases the reduced colors does not matter. Here is an example of reducing the colors to 254.

    convert -colors 254 in.png out.png
    
    0 讨论(0)
  • 2021-01-31 09:03

    You can try the pngquant utility. It is very simple to install and to use. And it can compress your PNGs a lot without visible quality loss.

    Once you install it try something like this:

    pngquant yourfile.png
    pngquant --quality=0-70 yourfile.png
    

    For my demo image (generated by imagemagick) the first command reduces 350KB to 110KB, and the second one reduces it to 65KB.

    0 讨论(0)
  • 2021-01-31 09:08

    I know you want to preserve the pixel size, but can you reduce the pixel size and adjust the DPI stored with the image so that the display size is preserved? It depends on what client you'll be using to view the images, but most should observe it. If you are using the images on the web, then you can just set the pixel size of the <img> tag.

    0 讨论(0)
  • 2021-01-31 09:09
    • Step 1: Decrease the image to 1/16 of its original size.
    • Step 2: Decrease the amount of colors.
    • Step 3: Increase the size of the image back to its original size.
    0 讨论(0)
  • 2021-01-31 09:14

    Since the size of an image file is directly related to the image dimensions and the number of colours, you seem to have only one choice: reduce the number of colours.

    And ~30MB down to 1MB is a very large reduction.

    It would be difficult to achieve this ratio with a conversion to monochrome.

    0 讨论(0)
  • 2021-01-31 09:21

    It depends on they type of image, is it a real life picture or computer generated image, for real life images png will do very little it might even not compress at all, use jpg for those images, it the image has a limited number of different colors (it can have a 24 bit image depth but the number of unique images will be low) png can compress quite nicely. png is basicly an implementation of zip for images so if a lot of pixels are the same you can have a rather nice compression ratio, if you need lossless compression don't do resizing.

    0 讨论(0)
提交回复
热议问题