• Editor
  • Exported PNG file size too big using script

Related Discussions
...

Hi,

I'm pretty new to the forums, so not sure if this is posted already. I searched the topic but i couldn't find the answer that I am looking for.

Every time I use the script to export the layers to png, each layer converted becomes 19MB. I have to use PNG Gauntlet to optimize each file after export.

Not sure what I am doing wrong or if I missed a setting.

Thanks!.

If you were to theoretically use a stronger PNG optimization setting, it would take forever to export your file.
I'm not sure if Photoshop actually lets you choose though. At least I know CS6 doesn't.

On the other hand, it being 19MB should be a function of how big and how complex your backing art is.
If you think the file sizes are disproportionately big considering their dimensions and complexity, maybe you could share one of those images?
And what is your basis for calling the file size "too big"? When would it be your expected size as opposed to "too big"?

Here are screenshots.

The dimensions are pretty small.

I exported in 16% and 1px padding.

I think the correct term was "hilariously large file sizes". XD

@Nate How is it even possible for a 40x33 png to be 20MB?

I can't even imagine. Adobe magicke! I did some tests and unspecified compression (ie no compression) was 20-30KB larger than max compression, using a relatively small sized PSD.

@jtamase, did you by chance try checking how much metadata was stored in the 19MB files ?

The script is doing "save as PNG", which I don't think strips metadata. We changed to that from "save for web" long ago for... reasons.

4 个月 后

The script is still doing the same thing. Do you guys think it has to do with the new versions of photoshop or any settings? or layer comps?


I found out that there might be some setting that my clients have with their PSD. Not sure what it is but I just opened a new file, copied all the flattened layers from the old file and exported using the script. It worked.

So I guess if this happens to anyone else, it's best to create a new.

2 年 后

Few days ago I switched to Photoshop CC from CS6 just to try it. I discovered the same thing - tiny bitmaps get extra megabytes out of nowhere when being saved as png in CC. The same bitmaps saved from CS6 are few kbytes. PsToSpine script has nothing to do with it. Adobe messed up someting in png saving module :/ So.. to my wallets pleasure i moved back to CS6 ;]

7 个月 后

Hello all!

I'm having the same issues since years now. I see this topic being quite old though.
Do we have any further detail about this issue? Do we at least know which kind of odd data is in those 16MB of PNG? (yea, for me the size is not 19, but 16,XX to all images... occasionally reaches 17 is the image is really big and complex)

The script does actually export correctly compressed PNGs sometimes, it seems to depend on some action you do on the PSD, which seems kind of irreversible.
For example, I noticed that if the PSD is a simple, plain document with just normal painted layers, the layers are exported fine.

If the PSD involves Smart Objects, it's probably going to be exported with the giant PNGs.

You could look at the PNG with TweakPNG and see what the extra data is. PNG allows any data to be stored in it. Image viewers and game toolkits should just skip data sections they don't understand.

The Photoshop script to save PNGs is just this:

function savePNG (file) {
   var options = new PNGSaveOptions();
   options.compression = 6;
   activeDocument.saveAs(file, options, true, Extension.LOWERCASE);
}

It used to use "save for web", but we changed it to "save as" because "save for web" was causing some problems (I don't remember exactly what).

I highly suggest OxiPNG. It's very fast and will make the smallest PNGs. It's used like:

oxipng -i 0 -o 4 

---

strip all yourfile.png

If you are on Mac or Linux or on Windows with Cygwin in your path, you can create a script like this:

set -x
ls *.png | while read line; do oxipng -i 0 -o 4 

---

strip all $line; done

This will apply OxiPNG to all PNG files in the current folder.

Hey Nate!

Thanks so much for the reply, and for the script :sun:

I tried with TweakPNG to exctract the content of one monster image... my suspicions were right, the part of the file that stores the actual image is just a microscopical part, worth in this case just 63KB, totally normal size.
The abomination occurs just before that, and is a text type of data.

It's such a long text string, that even trying to open, copy or paste it to read makes the PC struggle. I managed to paste it in a text editor, this is the beginning of the text:

<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?> 
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 6.0-c003 79.164527, 2020/10/15-17:48:32        "> 
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> 
<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#" xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#" xmlns:tiff="http://ns.adobe.com/tiff/1.0/" xmlns:exif="http://ns.adobe.com/exif/1.0/" xmp:CreatorTool="Adobe Photoshop 21.1 (Macintosh)" xmp:CreateDate="2020-04-01T14:10:33+02:00" xmp:MetadataDate="2021-02-20T12:39:53+01:00" xmp:ModifyDate="2021-02-20T12:39:53+01:00" photoshop:ColorMode="3" photoshop:ICCProfile="Display" dc:format="image/png" xmpMM:InstanceID="xmp.iid:414c3ea4-bf02-384d-aae5-84cc23663c00" xmpMM:DocumentID="adobe:docid:photoshop:1db3bbd0-6f5f-b248-82ea-13b6cdf3ab4f" xmpMM:OriginalDocumentID="xmp.did:c88f525a-6089-4966-8738-19df1ff99f47" tiff:Orientation="1" tiff:XResolution="720000/10000" tiff:YResolution="720000/10000" tiff:ResolutionUnit="2" exif:ColorSpace="65535" exif:PixelXDimension="1132" exif:PixelYDimension="939"> 
<photoshop:DocumentAncestors> 
<rdf:Bag> 
<rdf:li>0</rdf:li> 
<rdf:li>0000A6C7815905497C2762FB3073AC1B</rdf:li>
<rdf:li>00017C97C28B0C407DB5E9F93F00B063</rdf:li>
<rdf:li>000265C8AD52E62C75E64BBFC28B1C06</rdf:li>
<rdf:li>0002B2CA935E4B47910AC9252E59DC68</rdf:li>
<rdf:li>0003C8770168CFEB622F1A6523EA33CE</rdf:li>
<rdf:li>0004823E764D76354AA10DA511016E79</rdf:li>
<rdf:li>00057A1D9F9E6ECC2921B9FF3044122A</rdf:li>

... 

I put some new lines just for readability purpose, the original text is on one single line.
That list of <rdf:li> goes on forever, for such a high number of times that I think it has 0 to do with the actual image itself, it looks longer than the longest Fantasy saga ever written.
And at the end of the text part we find:

...

<rdf:li>xmp.id:FE7C5C7B47206811808399E50E9B1E6A</rdf:li>
<rdf:li>xmp.id:FE7F117407206811822A8003B198BBE4</rdf:li> 
<rdf:li>xmp.id:FE7F1174072068118C14A6CF03B26B14</rdf:li> 
<rdf:li>xmp.id:FF7F1174072068118C14F10C2D61E632</rdf:li> 
<rdf:li>xmp.id:a6c80afd-7b22-4916-8169-6e466407c52a</rdf:li>
 <rdf:li>xmp.id:ce2589c1-6db6-4c1e-aa4e-ad0e76710ff0</rdf:li>
 </rdf:Bag> 
</photoshop:DocumentAncestors> 
<xmpMM:History> 
<rdf:Seq> 
<rdf:li stEvt:action="created" stEvt:instanceID="xmp.iid:c88f525a-6089-4966-8738-19df1ff99f47" stEvt:when="2020-04-01T14:10:33+02:00" stEvt:softwareAgent="Adobe Photoshop 21.1 (Macintosh)"/> 
<rdf:li stEvt:action="saved" stEvt:instanceID="xmp.iid:616bc4cb-b073-4430-92c4-0875b4c5a27f" stEvt:when="2020-04-01T14:12:30+02:00" stEvt:softwareAgent="Adobe Photoshop 21.1 (Macintosh)" stEvt:changed="/"/>
<rdf:li stEvt:action="saved" stEvt:instanceID="xmp.iid:f37605a5-01db-1e4a-b564-b8b8569aebe3" stEvt:when="2021-02-20T12:39:52+01:00" stEvt:softwareAgent="Adobe Photoshop 22.1 (Windows)" stEvt:changed="/"/> 
<rdf:li stEvt:action="converted" stEvt:parameters="from application/vnd.adobe.photoshop to image/png"/> 
<rdf:li stEvt:action="derived" stEvt:parameters="converted from application/vnd.adobe.photoshop to image/png"/> 
<rdf:li stEvt:action="saved" stEvt:instanceID="xmp.iid:414c3ea4-bf02-384d-aae5-84cc23663c00" stEvt:when="2021-02-20T12:39:53+01:00" stEvt:softwareAgent="Adobe Photoshop 22.1 (Windows)" stEvt:changed="/"/> 
</rdf:Seq> 
</xmpMM:History> 
<xmpMM:DerivedFrom stRef:instanceID="xmp.iid:f37605a5-01db-1e4a-b564-b8b8569aebe3" stRef:documentID="xmp.did:c88f525a-6089-4966-8738-19df1ff99f47" stRef:originalDocumentID="xmp.did:c88f525a-6089-4966-8738-19df1ff99f47"/> 
</rdf:Description> 
</rdf:RDF> 
</x:xmpmeta> 
<?xpacket end="r"?>

I already use PNG Gauntlet to optimize PNGs, it does a good job but takes some time and manual inputs.
Alternatively to that small script you posted, would it be possible to modify my local copy of PStoSpine to make it try with Save For Web or Quick Export as PNG ?
If you just point me to a version of the script that used to have that, I can try to do it myself.

Thanks so much!

Huh, I wonder what that garbage PS writes is. How could they think that's a good idea?

A quick Google finds:
https://graphicdesign.stackexchange.com/questions/127123/exported-png-is-heavy-sized-than-generated-by-save-for-web
Could try that nasty code posted there, just replace the hardcoded path with the variable.

"Save for web" is shown here:
https://community.adobe.com/t5/photoshop/save-as-png-script/td-p/10627021