locked
Compress PNG Image ? RRS feed

  • Question

  • User1890471016 posted

    Hello World 

    I am using Generic Handler to Load Images. I am converting TIFF images to PNG Format. Now i need to compress the size of the PNG Image not the quality. Please suggest me the best free Image Compressor SDK.

    Please let me know asap

    Thursday, June 21, 2012 12:08 AM

Answers

  • User1622957740 posted

    There are a number of utilities out there to optimize PNG images like PNGOUT and OptiPng that are command line utilities. You can shell out from your ASP.NET app and call these to compress your images in place. Note though these tend to be pretty slow - it can take a while to optimize large images.

    However - TIFF images tend to be photos or photo-quality art, so generally PNG is not a good format for that. The problem is that PNG is lossless and it's not very good at very high res detailed content. You can *optimize* PNG by removing colors and transparency, but there's no way to 'compress' PNG.

    For photo-quality images if you want decent compression use JPEG or JPEG2000 (although that's not supported widely). Then play around with different image compression ratios. You can do JPeg compression with GDI+ if necessary or there are also command line utilities to do it for you.

    This StackOverFlow question lists a bunch of tools you can try:
    http://stackoverflow.com/questions/19153122/image-compression-tools-via-command-line

    +++ Rick ---

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 17, 2015 5:08 AM

All replies

  • User1890471016 posted

    Thanks for Reply...I do not want to specify any new size of image. Can we compress the original image with Original Size ?

    Friday, June 22, 2012 12:15 AM
  • User1890471016 posted

    Please let me know if there is any lossless image Compression algorithem in Asp.NET

    Tuesday, July 3, 2012 3:31 AM
  • User516094431 posted

    Please suggest me the best free Image Compressor SDK.

    you should use 7z sdk to compress and decompress a file:

    http://stackoverflow.com/questions/7646328/how-to-use-the-7z-sdk-to-compress-and-decompress-a-file

    More help full metrial:

    http://stackoverflow.com/questions/8340636/using-7zip-sdk-to-compress-a-file-but-the-archive-file-is-not-as-original-and-c

    http://geekswithblogs.net/bullpit/archive/2009/04/29/compress-image-files-using-c.aspx

    Tuesday, July 3, 2012 3:43 AM
  • User1890471016 posted

    How can i compress image using 7z. I think you not getting my question. When i am loading image from network i am getting TIFF image now i am converting TIFF to PNG and it takes 3.52 Sec to load image. I need to decrease that loading amount. I need to compress the image size not the quality....

    Wednesday, July 4, 2012 12:55 AM
  • User713976451 posted

    Hey,

    just came across this: One good strategy "to compress PNG" files is converting them into jpg since PNG compression is very limited in most cases and based on removing obsolete header information etc. With JPG you can reach a very high comrpession level which is what you want to have fast websites. A good service to convert png to jpg is the following one: It also allows multiple files www.png-to-jpg.com

    I use it for all my projects.

    Cheers!

    Wednesday, February 4, 2015 4:47 PM
  • User1622957740 posted

    There are a number of utilities out there to optimize PNG images like PNGOUT and OptiPng that are command line utilities. You can shell out from your ASP.NET app and call these to compress your images in place. Note though these tend to be pretty slow - it can take a while to optimize large images.

    However - TIFF images tend to be photos or photo-quality art, so generally PNG is not a good format for that. The problem is that PNG is lossless and it's not very good at very high res detailed content. You can *optimize* PNG by removing colors and transparency, but there's no way to 'compress' PNG.

    For photo-quality images if you want decent compression use JPEG or JPEG2000 (although that's not supported widely). Then play around with different image compression ratios. You can do JPeg compression with GDI+ if necessary or there are also command line utilities to do it for you.

    This StackOverFlow question lists a bunch of tools you can try:
    http://stackoverflow.com/questions/19153122/image-compression-tools-via-command-line

    +++ Rick ---

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 17, 2015 5:08 AM
  • User1622957740 posted

    Not a simple thing to do and it's very slow.

    The way I've done this is by shelling out to a tool like PngOut.exe to let it do the compression. Here's what I do on my blog with post images uploaded as part of my MetaWebLog API media uploads:

                    // png gets written here
                    bitmap.Save(ImagePhysicalPath);
    
                    if (Path.GetExtension(ImagePhysicalPath).ToLower() == ".png")
                    {
                        var pngOutPath = HttpContext.Current.Server.MapPath("~/") + "tools\\pngout.exe";                    
                        var p = Process.Start(pngOutPath, "\"" + ImagePhysicalPath + "\"");
                        p.ErrorDataReceived += (sender, e) =>
                        {
                            LogManager.Current.LogError("pngOut failed", e.Data);            
                        };
                    } 

    It works great, but it's pretty slow - all the compression tools I've seen and used are this slow so this inherent to the process of optimizing PNG in a lossless manner.

    Hope this helps,

    +++ Rick ---

    Monday, June 29, 2015 3:08 PM