Mystery: PNG File Size Shrinking

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ExpertAlmost
Forum Commoner
Posts: 41
Joined: Mon Oct 20, 2008 12:26 am

Mystery: PNG File Size Shrinking

Post by ExpertAlmost »

Good morning Experts!

My code creates a PNG file output 505 x 600 pixels, 24bit, 96dpi. The average file size is 130kb. No mystery there.

Here is the mystery: when I open the file using ACDSee (v10) and then "save as" (even with the same filename), the file size SHRINKS to about 80kb. All the specs remain the same and I can see no difference in the image! :o How in the world... What could an ACDSee file-save-as be doing and how do I do it in PHP? Doing a file-save-as in Windows Paint has the same result!

So I have tried to reduce the filesize in the code using compression and filters: from imagepng($Image, $ImageName) to imagepng($Image, $ImageName, 9, PNG_ALL_FILTERS). No difference. I tried running through PNGCRUSH, file size only goes to 112kb. The mystery is driving me crazy.

Any ideas of what to check in my code or image? Any ideas of tricks to try in the code? A 30% filesize reduction is too great to ignore.

I've attached a not-yet-shrunk file for your entertainment ;)

Thank you in advance for all your ideas!
File not shrunk
File not shrunk
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Mystery: PNG File Size Shrinking

Post by Weirdan »

Your image is interlaced. Converting it to non-interlaced image should help deflate filter to compress it more effectively.
ExpertAlmost
Forum Commoner
Posts: 41
Joined: Mon Oct 20, 2008 12:26 am

Re: Mystery: PNG File Size Shrinking

Post by ExpertAlmost »

Thank you very much Weirdan for your valuable insight!

I will try that out and see how it works this morning.

Have a great day :)
ExpertAlmost
Forum Commoner
Posts: 41
Joined: Mon Oct 20, 2008 12:26 am

Re: Mystery: PNG File Size Shrinking

Post by ExpertAlmost »

Just to close out the thread...

My original file was interlaced! Makes for a quicker load but a larger file. I saved my base image as NOT interlaced and threw in a imageinterlace($BscImg, 0); to make sure that anything else I did was not interlaced. Reduced file size from 124KB to 79KB. No other changes in palette or sizes.

Best of luck to all of you!
Post Reply