8 Replies Latest reply on May 2, 2012 2:12 PM by abu01

    Export Layers to Files Script Changing Resolution

    karistamps Level 1

      When I run this script to save my layers as .png files it turns them to  72 dpi  ... I need to keep them 300 dpi like  the original file. Is there a way to change that? Thanks in advance for any help!!


      Kari Holt

      iMac OS 10.5.8

      CS4 Extended

        • 1. Re: Export Layers to Files Script Changing Resolution
          Michael L Hale Level 5

          Export Layers to Files uses saveForWeb to save in the PNG format. You could replace the swf code with a normal save with options for the PNG24. That way the resolution info will not be striped from the metadata.

          • 2. Re: Export Layers to Files Script Changing Resolution
            karistamps Level 1

            Thanks for that information, Michael, but I know nothing about writing or chaging scripts I use PS primarily for digital scrapbook design and just want to be able to save my layers as trimmed png files at 300 dpi (which is the digital scrapbook "industry standard").  Any "easy" way to change it? I can open the script and even have a decent idea of where the PNG24 options are - just wouldn't know what to change or how to code it!

            • 3. Re: Export Layers to Files Script Changing Resolution
              biancapbd Level 1

              Hi, I'm a digiscrap designer too, and asked the same question a while ago. I came here to re-find the answer, cause it worked for me then, but somehow Photoshop decided to change the script back to the way it was... But the answer is here somewhere!

              • 4. Re: Export Layers to Files Script Changing Resolution
                Michael L Hale Level 5

                Open the script is a plain text editor. I recommend ExtendScript Toolkit that ships with Photoshop.


                Find the line case png24Index:


                Highlight everything between that line and the line that reads break. Replace with the code below.

                        case png24Index:
                            saveFile(docRef, fileNameBody, exportInfo, dlgMain.pnlFileType.pnlOptions.grpPNG24Options.png24Inter.value, dlgMain.pnlFileType.pnlOptions.grpPNG24Options.png24Trans.value);
                             function saveFile( docRef, fileNameBody, exportInfo, interlacedValue, transparencyValue) {
                               var id6 = charIDToTypeID( "Expr" );
                                    var desc3 = new ActionDescriptor();
                                    var id7 = charIDToTypeID( "Usng" );
                                         var desc4 = new ActionDescriptor();
                                         var id8 = charIDToTypeID( "Op  " );
                                         var id9 = charIDToTypeID( "SWOp" );
                                         var id10 = charIDToTypeID( "OpSa" );
                                       desc4.putEnumerated( id8, id9, id10 );
                                         var id11 = charIDToTypeID( "Fmt " );
                                         var id12 = charIDToTypeID( "IRFm" );
                                         var id13 = charIDToTypeID( "PN24" );
                                         desc4.putEnumerated( id11, id12, id13 );
                                         var id14 = charIDToTypeID( "Intr" );
                                         desc4.putBoolean( id14, interlacedValue );
                                         var id15 = charIDToTypeID( "Trns" );
                                         desc4.putBoolean( id15, transparencyValue );
                                         var id16 = charIDToTypeID( "Mtt " );
                                         desc4.putBoolean( id16, true );
                                         var id17 = charIDToTypeID( "MttR" );
                                         desc4.putInteger( id17, 255 );
                                         var id18 = charIDToTypeID( "MttG" );
                                         desc4.putInteger( id18, 255 );
                                         var id19 = charIDToTypeID( "MttB" );
                                         desc4.putInteger( id19, 255 );
                                         var id20 = charIDToTypeID( "SHTM" );
                                         desc4.putBoolean( id20, false );
                                         var id21 = charIDToTypeID( "SImg" );
                                         desc4.putBoolean( id21, true );
                                         var id22 = charIDToTypeID( "SSSO" );
                                         desc4.putBoolean( id22, false );
                                         var id23 = charIDToTypeID( "SSLt" );
                                              var list1 = new ActionList();
                                         desc4.putList( id23, list1 );
                                         var id24 = charIDToTypeID( "DIDr" );
                                         desc4.putBoolean( id24, false );
                                         var id25 = charIDToTypeID( "In  " );
                                         desc4.putPath( id25, new File( exportInfo.destination + "/" + fileNameBody + ".png") );
                                    var id26 = stringIDToTypeID( "SaveForWeb" );
                                    desc3.putObject( id7, id26, desc4 );
                               executeAction( id6, desc3, DialogModes.NO );
                            var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".png");
                            pngSaveOptions = new PNGSaveOptions();
                            pngSaveOptions.interlaced = false;
                            docRef.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);


                Note this comments out the saveForWeb code rather then deletes it should you want to revert back. It also removes the comment chars from the existing normal save code and corrects the save option used from bmp to png.


                I would also recommend that you add comments to the top of the script noting that you edited the script and save it using a different name.

                • 5. Re: Export Layers to Files Script Changing Resolution
                  karistamps Level 1

                  WOW, Michael!! Thank you so much for the code ... I copied it and it seems to be working for me to keep the file size at 300 dpi I can't thank you enough for your help - this will save me so much time!

                  • 6. Re: Export Layers to Files Script Changing Resolution
                    LaurieAnnis Level 1

                    I am having a similar issue, except that I need to save each layer as a .jpg, and the Export Layers to Files script is compressing the images in some fashion so that a previously seamlessly tiling layer now has a border that ruins the tile.  If I save each layer individually using either the Save As command or Save for Web and Devices with the proper settings (Maximum Quality, Progressive, and Baseline Standard), the resulting images don't acquire this border, so I feel pretty certain it is something in the script that is messing up (changing the compression of) the layers, but I honestly don't know what.  I have tried modifiying the jpeg portion of the script this way, hoping to prevent it from deviating from the usual Save As options:


                            case jpegIndex:
                                docRef.bitsPerChannel = BitsPerChannelType.EIGHT;
                                var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".jpg");
                                jpgSaveOptions = new JPEGSaveOptions();
                                jpgSaveOptions.embedColorProfile = true;
                                jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
                                jpgSaveOptions.matte = MatteType.NONE;
                                jpgSaveOptions.quality = jpegQuality; // 12
                                docRef.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);


                    but this doesn't seem to affect whatever setting is being changed.  Layers saved to .jpg this way still acquire the border.  I don't see what line might control whether the image is saved as progressive or not, nor anything to affect the text setting "Maximum" that I use when I successfully save each layer individually.


                    I am a complete novice at scripting, so please excuse/explain the obvious mistakes I may be making here.

                    • 7. Re: Export Layers to Files Script Changing Resolution
                      pauljmackay Level 1



                      I've tried this script change in CS4 and find that it then shows a dialog for saving a PSD file and hence is not automated. Should this work such that it automatically saves each PNG as the original one does?


                      Any help with this is much appreciated!





                      • 8. Re: Export Layers to Files Script Changing Resolution
                        abu01 Level 1

                        I loaded the script by Michael L Hale listed in this thread and it works for keeping the resolution at 300 dpi, but now I don't have an option to trim the png before saving.  Is there a line in the code that can be edited to allow trimming of the pngs?  I'm working in CS4 and know nothing about scripting .  Thank you in advance for any help you can give!