13 Replies Latest reply on Aug 24, 2015 6:23 AM by ACS LLC

    compressing PNG images

    ACS LLC Level 1

      I have a script that captures PNG images from a 3rd party server, I then save them on my server using  this code, forcing them to 45x45

       

      <cfimage

          action = "resize"

          height = "45"

          width  = "45"

          source = "#objImage#"

          destination = "#newFileName#"

          overwrite = "yes">

       

      The issue I see is that the file sizes are nowhere near as low as they could be, I dropped a few of them into tinypng.com and they can be reduced by as much as 75%, and at least 50% with no noticeable loss in visual quality.

       

      The question is, does anybody have a method to compress PNG's? I see that the quality="" is only suitable for JPGS

       

      Btw I'm running this on CF8

        • 1. Re: compressing PNG images
          mack_ Level 3

          Try running pngout and/or pngcrush on them.

          • 2. Re: compressing PNG images
            ACS LLC Level 1

            Thanks for the reply. Is pngout / pngcrush similar to tinypng, or is it a component that I can install and run using the CF code?

            • 3. Re: compressing PNG images
              mack_ Level 3

              Thanks for the reply. Is pngout / pngcrush similar to tinypng, or is it a

              component that I can install and run using the CF code?

               

              Both are compiled programs that you can run with CFEXECUTE from ColdFusion.

              • 4. Re: compressing PNG images
                ACS LLC Level 1

                ahh. got it, so I can install and use command line to run them using CFEXECUTE, it's many years since I've done anything like this in the past, I'll play around and see if I can figure it out.

                 

                (I did try pngcrush on their site and received a slight saving so it was not as good as tinypng)

                • 5. Re: compressing PNG images
                  ACS LLC Level 1

                  pngcrush uses an API, and I need it to always be running on my server, pngout I might be able to CFEXECUTE, BUT both of them give poor reduction results, I've emailed pngout to see if the developer has any ideas. tinypng is MUCH better but it's an API only setup

                  • 6. Re: compressing PNG images
                    mack_ Level 3

                    (I did try pngcrush on their site and received a

                    slight saving so it was not as good as tinypng)

                     

                    tinypng seems to have an API that you can use:

                    https://tinypng.com/developers

                    • 7. Re: compressing PNG images
                      ACS LLC Level 1

                      They do, but they charge for the number of images and I'm going to have a LOT of images to process, on top of that I don't want to have to rely on a 3rd party, I want the whole process to take place on my server

                      • 8. Re: compressing PNG images
                        mack_ Level 3

                        They do, but they charge for the number of images and I'm going to

                        have a LOT of images to process, on top of that I don't want to have

                        to rely on a 3rd party, I want the whole process to take place on my

                        server

                         

                        In that case I think pngout or pngcrush are your best options.

                        • 9. Re: compressing PNG images
                          ACS LLC Level 1

                          It looked like pingcrush was also API running on their server only.

                           

                          I managed to get 20% compression on pingout, compared to 75% on tinypng

                          • 10. Re: compressing PNG images
                            mack_ Level 3

                            It looked like pingcrush was also API running on their server only.

                             

                            Actually I was referring to this pngcrush

                            http://pmt.sourceforge.net/pngcrush/

                            • 11. Re: compressing PNG images
                              ACS LLC Level 1

                              I did receive a reply from pngout

                               

                              "The landing page for tinypng states that it is lossy: it dithers (aka quantizes) the image.

                                PNGOUT never dithers. "


                              It looks like pngcrush does the same thing because like pngout, the savings on file size are not that great. I'll dig into it a little more to see if there is an option to apply a dither

                              • 12. Re: compressing PNG images
                                Jamo Level 2

                                GraphicsMagick has some PNG options... I wrote a custom tag to use on ColdFusion 8-11. GM supports 88 format and provides safer & faster manipulations. (It works with CMYK JPGs without compatibility or HEAP issues):
                                http://gamesover2600.tumblr.com/post/125766251344/graphicsmagick-coldfusion-custom-tag

                                 

                                If you use GraphicsMagick, you'll be able to tweak the optimization settings too and generate thumbnails for an entire sub-directory with a single call.

                                 

                                Here's an article from SmashingMagazine regarding good compression settings for ImageMagick (similar to GraphicsMagick):
                                http://www.smashingmagazine.com/2015/06/efficient-image-resizing-with-imagemagick/

                                 

                                I'm also working on using ColdFusion with ExifTool. Using ImageRead() to determine if an image is CMYK has caused us a lot of performance problems. (80 seconds versus 300-500ms.)

                                • 13. Re: compressing PNG images
                                  ACS LLC Level 1

                                  It looks like I have a solution.

                                   

                                  The good people at PNGout ( http://www.ardfry.com ) told me to check out https://pngquant.org/ which uses lossy compression, by dithering (aka quantizes) the image.


                                  Looking at their site it appeared that they have different ways to test their software with links to third parties who use their software, one of them being http://www.tinyPNG.org , as you'll see in my thread above I wanted to produce the same excellent results of tinypng.


                                  I downloaded the pngquant command line version for Windows and used CFEXECUTE to run it, it was super easy -->

                                   

                                  <cfexecute name = "d:\pngquant.exe"

                                  arguments = "d:\232.png --ext .png --force --speed 5"

                                  outputFile = ""

                                  timeout = "60">

                                  </cfexecute>

                                   

                                  In order for it not to create a new file but overwrite the original, I added --ext .png , otherwise you end up with two images

                                   

                                  I noticed I could get it to run around twice as fast with -- speed 5, and still get the same amazing results, dropping 20k images down to around 5k, with no obvious drop in visual quality, if you go for -- speed 11, the fastest it can be a lot quicker, but the file sizes although still much smaller are not at their smallest.

                                   

                                  The only argument I did have trouble with was -- skip-if-larger which is supposed to skip creation of the image if the results of the new image are actually larger than the original, however when I tried it I found that the new image would not create even though it would indeed be smaller (I've emailed them regarding this problem)

                                   

                                  Ardfry did suggest that I then run the image through their lossless pngout to gain further on file size reduction, the tests I did with this did help, but only by around 2% or so.

                                   

                                  This does appear to be a good clean solution, that is reasonably quick so I'll make this as the correct answer.

                                   

                                  Thanks for your input.