Highlighted

compressing PNG images

Enthusiast ,
Aug 20, 2015

Copy link to clipboard

Copied

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

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.

Views

976

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

compressing PNG images

Enthusiast ,
Aug 20, 2015

Copy link to clipboard

Copied

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

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.

Views

977

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 20, 2015 0
Enthusiast ,
Aug 20, 2015

Copy link to clipboard

Copied

Try running pngout and/or pngcrush on them.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2015 0
Enthusiast ,
Aug 20, 2015

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2015 0
Enthusiast ,
Aug 20, 2015

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2015 0
Enthusiast ,
Aug 20, 2015

Copy link to clipboard

Copied

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)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2015 0
Enthusiast ,
Aug 20, 2015

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2015 0
Enthusiast ,
Aug 20, 2015

Copy link to clipboard

Copied

(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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2015 0
Enthusiast ,
Aug 20, 2015

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2015 0
Enthusiast ,
Aug 20, 2015

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2015 0
Enthusiast ,
Aug 20, 2015

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2015 0
Enthusiast ,
Aug 20, 2015

Copy link to clipboard

Copied

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

Actually I was referring to this pngcrush

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2015 0
Enthusiast ,
Aug 20, 2015

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2015 0
Engaged ,
Aug 20, 2015

Copy link to clipboard

Copied

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.)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2015 0
Enthusiast ,
Aug 24, 2015

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 24, 2015 0