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 😉 (It appears that the upload program converts my file to a gif file which is less than 100kb. The original is 120kb)

Thank you in advance for all your ideas!

    because not every algorithm to create a png file or jpg or ... is the same.

      Thank you Dagon for your reply!

      So what do you suggest I do in my code to take advantage of the situation? Or what would you say I might be doing wrong that I am adding 30% file size?

      Keep those cards and letters coming folks... 😉

        I'm guessing it converts it from RGB (e.g. truecolor) to indexed (e.g. palette-based).

          Thank you NogDog for your reply.

          If that is true, I would I accomplish myself in PHP to test that theory? Or reduce my file size?

          Cheers!

            <?php
            $origFile = 'foo\Pictures\5star.png';
            $origSize = filesize($origFile);
            $src = imagecreatefrompng($origFile);
            $sizeInfo = getimagesize($origFile);
            $new = imagecreate($sizeInfo[0], $sizeInfo[1]);
            imagecopyresampled($new, $src, 0, 0, 0, 0, $sizeInfo[0], $sizeInfo[1], $sizeInfo[0], $sizeInfo[1]);
            $newFile = 'foo\Pictures\new5star.png';
            imagepng($new, $newFile, 9);
            $newSize = filesize($newFile);
            echo "$origSize -> $newSize";
            

            Output:

            35270 -> 18495
            

              WOW! And that works? How in the world... hahahah

              I will give it a try and report back :-)

              Thank you very much nogdog!

                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.

                Thank you everyone and best of luck to all of you!

                  Write a Reply...