Skip to main content
Participating Frequently
July 9, 2010
質問

modding the Export Layers to Files script to preserve .jpg quality

  • July 9, 2010
  • 返信数 2.
  • 3967 ビュー

Please forgive me if I am posting this incorrectly, but as the thread I initially replied to is marked as Answered I started to wonder whether my question would be seen or not so I started this new thread.  My original question is located in the thread http://forums.adobe.com/message/2795719#2795719 because Kari was having a similar issue to mine, but with a different file format.  My original text:

--------------------------------------------

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);
            break;

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.

----------------------------

I have since installed the script listener plug in and isolated a bit of script for saving the intended way, and hope to insert this snippet into the Export Layers as Files script, but I can tell that some of the lines are extraneous (like where it points to the file path I took), but I don't know what is safe to trim out.  I sincerely appreciate any assistance with this!

このトピックへの返信は締め切られました。

返信数 2

LaurieAnnis作成者
Participating Frequently
July 10, 2010

Thank you so much again.  I was able to run it this way, but the border still appeared, so I have spent the evening examining other parts of the script and have made an unexpected discovery.  Apparently, the Export Layers to Files script works by duplicating each file into its own file, and then saving that file with the user's settings.  I ran a simple test of duplicating a layer into a new file and offsetting THAT texture and voiala, the border appeared.  So something about the part where it duplicates the layers into a new file for saving is where the distortion is occurring, rather than in the save settings.

I am so sorry to have unintentionally led a wild goose chase, but I am glad that I found this out.  I am still not sure what to do to prevent the script from duplicating the layers into new files in order to save them, partly because I don't understand why that would have been done in the first place, but I will keep running some tests.  Does this make any sense to you, and do you have any ideas for how to force the script to save each layer without duplicating it out?  I am thinking something along the lines of hiding/unhiding each layer in a sequence and saving the current state each time.

LaurieAnnis作成者
Participating Frequently
July 10, 2010

Looks like I was wrong again.  My resized images were the culprit, having acquired some loss of information along the border, but the border was being obscured in the .psd file by any visible layer beneath.  That's why it appeared to be happening in the duplication process, because that was the only point when I was seeing each layer isolated with nothing behind it to obscure the distorted area (which is about a pixel wide all the way around), and that was why saving from the .psd as a .jpg was working, because it was flattening the offending layers with the visible layers behind them.  My mind is just spinning.  I think an easy fix will be to duplicate and merge every layer with a copy of itself because this seems to bolster that border somehow, but I'm reluctant to dive in after being wrong so many times.  I really do appreciate your help with the script!

Inspiring
July 10, 2010

I didn't think that the way Export Layers to Files was saving the jpeg was the reason for your problem but I have seen stranger things that don't make sense and it was easy enough to change to see if that was the reason.

Hope you find a way to get the results you need.

Inspiring
July 9, 2010

I'm not sure why you are getting a border. You can set jpgSaveOptions.formatOptions to FormatOptions.OPTIMIZEDBASELINE, FormatOptions.PROGRESSIVE, or FormatOptions.STANDARDBASELINE. STANDARDBASELINE is the safest if you are going to display in a web browser according to the guide.

If you post your scriptlistener code I will show you how to adapt and add it to Export Layers to Files.

LaurieAnnis作成者
Participating Frequently
July 9, 2010

Thank you so much!  I'm not sure what setting is being changed or ignored in the original Export Layers to Files script but it is definitely not acceptable.  There are a few more sliders when you use the Save As dialogue than the script presents to you, though they look redundant to me, but I am hoping that the key to preserving the intended settings is including what the listener picked up, although -- novice that I am -- I don't see anything extra here that isn't in the original script.  I must wonder if the Save for Web and Devices script encompasses more of the settings.  All I recognize in the Save As script is the Quality setting at 12 (which the original script already includes).   The Save As method produces a much shorter script, so the first script below is what it gives me when I do a simple Save As .jpeg, the second script is when I do Save for Web and Devices:

// =======================================================
var idsave = charIDToTypeID( "save" );
    var desc4 = new ActionDescriptor();
    var idAs = charIDToTypeID( "As  " );
        var desc5 = new ActionDescriptor();
        var idEQlt = charIDToTypeID( "EQlt" );
        desc5.putInteger( idEQlt, 12 );
        var idMttC = charIDToTypeID( "MttC" );
        var idMttC = charIDToTypeID( "MttC" );
        var idNone = charIDToTypeID( "None" );
        desc5.putEnumerated( idMttC, idMttC, idNone );
    var idJPEG = charIDToTypeID( "JPEG" );
    desc4.putObject( idAs, idJPEG, desc5 );
    var idIn = charIDToTypeID( "In  " );
    desc4.putPath( idIn, new File( "C:\\Users\\MYFILEPATH" ) );
    var idCpy = charIDToTypeID( "Cpy " );
    desc4.putBoolean( idCpy, true );
executeAction( idsave, desc4, DialogModes.NO );

// =======================================================
var idExpr = charIDToTypeID( "Expr" );
    var desc9 = new ActionDescriptor();
    var idUsng = charIDToTypeID( "Usng" );
        var desc10 = new ActionDescriptor();
        var idOp = charIDToTypeID( "Op  " );
        var idSWOp = charIDToTypeID( "SWOp" );
        var idOpSa = charIDToTypeID( "OpSa" );
        desc10.putEnumerated( idOp, idSWOp, idOpSa );
        var idDIDr = charIDToTypeID( "DIDr" );
        desc10.putBoolean( idDIDr, false );
        var idIn = charIDToTypeID( "In  " );
        desc10.putPath( idIn, new File( "C:\\Users\\MYFILEPATH" ) );
        var idFmt = charIDToTypeID( "Fmt " );
        var idIRFm = charIDToTypeID( "IRFm" );
        var idJPEG = charIDToTypeID( "JPEG" );
        desc10.putEnumerated( idFmt, idIRFm, idJPEG );
        var idIntr = charIDToTypeID( "Intr" );
        desc10.putBoolean( idIntr, false );
        var idQlty = charIDToTypeID( "Qlty" );
        desc10.putInteger( idQlty, 100 );
        var idQChS = charIDToTypeID( "QChS" );
        desc10.putInteger( idQChS, 0 );
        var idQCUI = charIDToTypeID( "QCUI" );
        desc10.putInteger( idQCUI, 0 );
        var idQChT = charIDToTypeID( "QChT" );
        desc10.putBoolean( idQChT, false );
        var idQChV = charIDToTypeID( "QChV" );
        desc10.putBoolean( idQChV, false );
        var idOptm = charIDToTypeID( "Optm" );
        desc10.putBoolean( idOptm, true );
        var idPass = charIDToTypeID( "Pass" );
        desc10.putInteger( idPass, 3 );
        var idblur = charIDToTypeID( "blur" );
        desc10.putDouble( idblur, 0.000000 );
        var idEICC = charIDToTypeID( "EICC" );
        desc10.putBoolean( idEICC, false );
        var idMtt = charIDToTypeID( "Mtt " );
        desc10.putBoolean( idMtt, false );
        var idMttR = charIDToTypeID( "MttR" );
        desc10.putInteger( idMttR, 0 );
        var idMttG = charIDToTypeID( "MttG" );
        desc10.putInteger( idMttG, 0 );
        var idMttB = charIDToTypeID( "MttB" );
        desc10.putInteger( idMttB, 0 );
        var idSHTM = charIDToTypeID( "SHTM" );
        desc10.putBoolean( idSHTM, false );
        var idSImg = charIDToTypeID( "SImg" );
        desc10.putBoolean( idSImg, true );
        var idSWsl = charIDToTypeID( "SWsl" );
        var idSTsl = charIDToTypeID( "STsl" );
        var idSLAl = charIDToTypeID( "SLAl" );
        desc10.putEnumerated( idSWsl, idSTsl, idSLAl );
        var idSWch = charIDToTypeID( "SWch" );
        var idSTch = charIDToTypeID( "STch" );
        var idCHDc = charIDToTypeID( "CHDc" );
        desc10.putEnumerated( idSWch, idSTch, idCHDc );
        var idSWmd = charIDToTypeID( "SWmd" );
        var idSTmd = charIDToTypeID( "STmd" );
        var idMDCC = charIDToTypeID( "MDCC" );
        desc10.putEnumerated( idSWmd, idSTmd, idMDCC );
        var idohXH = charIDToTypeID( "ohXH" );
        desc10.putBoolean( idohXH, false );
        var idohIC = charIDToTypeID( "ohIC" );
        desc10.putBoolean( idohIC, true );
        var idohAA = charIDToTypeID( "ohAA" );
        desc10.putBoolean( idohAA, true );
        var idohQA = charIDToTypeID( "ohQA" );
        desc10.putBoolean( idohQA, true );
        var idohCA = charIDToTypeID( "ohCA" );
        desc10.putBoolean( idohCA, false );
        var idohIZ = charIDToTypeID( "ohIZ" );
        desc10.putBoolean( idohIZ, true );
        var idohTC = charIDToTypeID( "ohTC" );
        var idSToc = charIDToTypeID( "SToc" );
        var idOCzerothree = charIDToTypeID( "OC03" );
        desc10.putEnumerated( idohTC, idSToc, idOCzerothree );
        var idohAC = charIDToTypeID( "ohAC" );
        var idSToc = charIDToTypeID( "SToc" );
        var idOCzerothree = charIDToTypeID( "OC03" );
        desc10.putEnumerated( idohAC, idSToc, idOCzerothree );
        var idohIn = charIDToTypeID( "ohIn" );
        desc10.putInteger( idohIn, -1 );
        var idohLE = charIDToTypeID( "ohLE" );
        var idSTle = charIDToTypeID( "STle" );
        var idLEzerothree = charIDToTypeID( "LE03" );
        desc10.putEnumerated( idohLE, idSTle, idLEzerothree );
        var idohEn = charIDToTypeID( "ohEn" );
        var idSTen = charIDToTypeID( "STen" );
        var idENzerozero = charIDToTypeID( "EN00" );
        desc10.putEnumerated( idohEn, idSTen, idENzerozero );
        var idolCS = charIDToTypeID( "olCS" );
        desc10.putBoolean( idolCS, false );
        var idolEC = charIDToTypeID( "olEC" );
        var idSTst = charIDToTypeID( "STst" );
        var idSTzerozero = charIDToTypeID( "ST00" );
        desc10.putEnumerated( idolEC, idSTst, idSTzerozero );
        var idolWH = charIDToTypeID( "olWH" );
        var idSTwh = charIDToTypeID( "STwh" );
        var idWHzeroone = charIDToTypeID( "WH01" );
        desc10.putEnumerated( idolWH, idSTwh, idWHzeroone );
        var idolSV = charIDToTypeID( "olSV" );
        var idSTsp = charIDToTypeID( "STsp" );
        var idSPzerofour = charIDToTypeID( "SP04" );
        desc10.putEnumerated( idolSV, idSTsp, idSPzerofour );
        var idolSH = charIDToTypeID( "olSH" );
        var idSTsp = charIDToTypeID( "STsp" );
        var idSPzerofour = charIDToTypeID( "SP04" );
        desc10.putEnumerated( idolSH, idSTsp, idSPzerofour );
        var idolNC = charIDToTypeID( "olNC" );
            var list3 = new ActionList();
                var desc11 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCzerozero = charIDToTypeID( "NC00" );
                desc11.putEnumerated( idncTp, idSTnc, idNCzerozero );
            var idSCnc = charIDToTypeID( "SCnc" );
            list3.putObject( idSCnc, desc11 );
                var desc12 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNConenine = charIDToTypeID( "NC19" );
                desc12.putEnumerated( idncTp, idSTnc, idNConenine );
            var idSCnc = charIDToTypeID( "SCnc" );
            list3.putObject( idSCnc, desc12 );
                var desc13 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwoeight = charIDToTypeID( "NC28" );
                desc13.putEnumerated( idncTp, idSTnc, idNCtwoeight );
            var idSCnc = charIDToTypeID( "SCnc" );
            list3.putObject( idSCnc, desc13 );
                var desc14 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc14.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list3.putObject( idSCnc, desc14 );
                var desc15 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc15.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list3.putObject( idSCnc, desc15 );
                var desc16 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc16.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list3.putObject( idSCnc, desc16 );
        desc10.putList( idolNC, list3 );
        var idobIA = charIDToTypeID( "obIA" );
        desc10.putBoolean( idobIA, false );
        var idobIP = charIDToTypeID( "obIP" );
        desc10.putString( idobIP, "" );
        var idobCS = charIDToTypeID( "obCS" );
        var idSTcs = charIDToTypeID( "STcs" );
        var idCSzeroone = charIDToTypeID( "CS01" );
        desc10.putEnumerated( idobCS, idSTcs, idCSzeroone );
        var idovNC = charIDToTypeID( "ovNC" );
            var list4 = new ActionList();
                var desc17 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCzerozero = charIDToTypeID( "NC00" );
                desc17.putEnumerated( idncTp, idSTnc, idNCzerozero );
            var idSCnc = charIDToTypeID( "SCnc" );
            list4.putObject( idSCnc, desc17 );
                var desc18 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNConenine = charIDToTypeID( "NC19" );
                desc18.putEnumerated( idncTp, idSTnc, idNConenine );
            var idSCnc = charIDToTypeID( "SCnc" );
            list4.putObject( idSCnc, desc18 );
                var desc19 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc19.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list4.putObject( idSCnc, desc19 );
                var desc20 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc20.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list4.putObject( idSCnc, desc20 );
                var desc21 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc21.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list4.putObject( idSCnc, desc21 );
                var desc22 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc22.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list4.putObject( idSCnc, desc22 );
                var desc23 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc23.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list4.putObject( idSCnc, desc23 );
                var desc24 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc24.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list4.putObject( idSCnc, desc24 );
                var desc25 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwotwo = charIDToTypeID( "NC22" );
                desc25.putEnumerated( idncTp, idSTnc, idNCtwotwo );
            var idSCnc = charIDToTypeID( "SCnc" );
            list4.putObject( idSCnc, desc25 );
        desc10.putList( idovNC, list4 );
        var idovCM = charIDToTypeID( "ovCM" );
        desc10.putBoolean( idovCM, false );
        var idovCW = charIDToTypeID( "ovCW" );
        desc10.putBoolean( idovCW, true );
        var idovCU = charIDToTypeID( "ovCU" );
        desc10.putBoolean( idovCU, false );
        var idovSF = charIDToTypeID( "ovSF" );
        desc10.putBoolean( idovSF, false );
        var idovCB = charIDToTypeID( "ovCB" );
        desc10.putBoolean( idovCB, false );
    var idSaveForWeb = stringIDToTypeID( "SaveForWeb" );
    desc9.putObject( idUsng, idSaveForWeb, desc10 );
executeAction( idExpr, desc9, DialogModes.NO );

LaurieAnnis作成者
Participating Frequently
July 9, 2010

By the way, in case you find it as troublesome as I do that this border is being created at all, I should note that I am saving layers of a .psd to .jpg format at a variety of sizes and resolutions, and this only crops up at the lowest resolution/scale settings that is required for the job, so the image is already a bit degraded by the process of resizing (image size 512 x 512, 72dpi down from 1024 x 1024, 150dpi, using Bilinear resampling else the border appears instnatly), but again, I can save each layer one at a time at just the right settings and obtain an acceptable result while for some reason the export script does something undesireable to the final .jpg.