• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

I can't create a Photoshop Script that saves a High Quality Gif :(

Participant ,
Jan 28, 2020 Jan 28, 2020

Copy link to clipboard

Copied

I'm struggling for a long time trying to make a Photoshop Script that needs to save my GIF with the best settings. I've a preset I use that save my GIFs with the best quality I can get. These are the settings I'm using for high quality:

 

settings_gif.pngexpand image

But, when I'm trying to run my script, even if I set the same settings it doens't save my gif as the same quality as my preset.

 

Like in these two images:

 

Saving with the preset in Photoshop

Saving with Photoshop PresetSaving with Photoshop Presetexpand image

 

Saving with the script

Saving with ScriptSaving with Scriptexpand image

 

This is my script:

 

#target photoshop
app.bringToFront();

var doc = activeDocument;

function saveGIF (fileName){
        
        var myFile = new File(doc.path + "/" + fileName + ".gif")
                
        var gifOptions = new ExportOptionsSaveForWeb(); 
        
        gifOptions.format = SaveDocumentType.COMPUSERVEGIF; 
        gifOptions.ColorReductionType = ColorReductionType.SELECTIVE;
        gifOptions.dither = Dither.DIFFUSION;
        gifOptions.ditherAmout = 100;
        gifOptions.colors = 256;
        gifOptions.interlaced = true;
        gifOptions.transparency = true;
        gifOptions.transparencyAmount = 100;
        gifOptions.transparencyDither = Dither.NONE;
        gifOptions.webSnap = 0;
        gifOptions.quality = 100;
        gifOptions.lossy = 0;       
                
        doc.exportDocument(myFile, ExportType.SAVEFORWEB, gifOptions);
    
}


var fileName = doc.name.replace(/.\w+$/,"");

saveGIF(fileName);

 

 

Does someone knows what am I doing wrong? Or how can I solve this problem?

Thanks! 🙂

 

TOPICS
Actions and scripting

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Jan 28, 2020 Jan 28, 2020

Thanks!

 

Looks like I could solve by using the "GIFSaveOptions" instead of using the "ExportOptionsSaveForWeb" method.

I hope it will work in all files, I've made a few tests here and it worked.

 

The way it worked is like this:

 

 

#target photoshop
app.bringToFront();

var doc = activeDocument;

function saveGIF (fileName){
        
        var myFile = new File(doc.path + "/" + fileName + ".gif")
                
        var gifOptions = new GIFSaveOptions(); 
        
        gifOptions.palette = P
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 28, 2020 Jan 28, 2020

Copy link to clipboard

Copied

Have you tried generating you code with scriptListener to get Action Manager code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 28, 2020 Jan 28, 2020

Copy link to clipboard

Copied

I just tried something like this:

 

#target photoshop
app.bringToFront();

var doc = activeDocument;

function saveGIF (fileName){
    var idExpr = charIDToTypeID( "Expr" );
    var desc634 = new ActionDescriptor();
    var idUsng = charIDToTypeID( "Usng" );
        var desc635 = new ActionDescriptor();
        var idOp = charIDToTypeID( "Op  " );
        var idSWOp = charIDToTypeID( "SWOp" );
        var idOpSa = charIDToTypeID( "OpSa" );
        desc635.putEnumerated( idOp, idSWOp, idOpSa );
        var idDIDr = charIDToTypeID( "DIDr" );
        desc635.putBoolean( idDIDr, true );
        var idIn = charIDToTypeID( "In  " );
        desc635.putPath( idIn, new File(doc.path) );
        var idovFN = charIDToTypeID( "ovFN" );
        desc635.putString( idovFN, fileName );
        var idFmt = charIDToTypeID( "Fmt " );
        var idIRFm = charIDToTypeID( "IRFm" );
        var idGIFf = charIDToTypeID( "GIFf" );
        desc635.putEnumerated( idFmt, idIRFm, idGIFf );
        var idIntr = charIDToTypeID( "Intr" );
        desc635.putBoolean( idIntr, true );
        var idRedA = charIDToTypeID( "RedA" );
        var idIRRd = charIDToTypeID( "IRRd" );
        var idSltv = charIDToTypeID( "Sltv" );
        desc635.putEnumerated( idRedA, idIRRd, idSltv );
        var idRChT = charIDToTypeID( "RChT" );
        desc635.putBoolean( idRChT, false );
        var idRChV = charIDToTypeID( "RChV" );
        desc635.putBoolean( idRChV, false );
        var idAuRd = charIDToTypeID( "AuRd" );
        desc635.putBoolean( idAuRd, false );
        var idNCol = charIDToTypeID( "NCol" );
        desc635.putInteger( idNCol, 256 );
        var idDChS = charIDToTypeID( "DChS" );
        desc635.putInteger( idDChS, 0 );
        var idDCUI = charIDToTypeID( "DCUI" );
        desc635.putInteger( idDCUI, 0 );
        var idDChT = charIDToTypeID( "DChT" );
        desc635.putBoolean( idDChT, false );
        var idDChV = charIDToTypeID( "DChV" );
        desc635.putBoolean( idDChV, false );
        var idWebS = charIDToTypeID( "WebS" );
        desc635.putInteger( idWebS, 0 );
        var idTDth = charIDToTypeID( "TDth" );
        var idIRDt = charIDToTypeID( "IRDt" );
        var idNone = charIDToTypeID( "None" );
        desc635.putEnumerated( idTDth, idIRDt, idNone );
        var idTDtA = charIDToTypeID( "TDtA" );
        desc635.putInteger( idTDtA, 100 );
        var idLoss = charIDToTypeID( "Loss" );
        desc635.putInteger( idLoss, 0 );
        var idLChS = charIDToTypeID( "LChS" );
        desc635.putInteger( idLChS, 0 );
        var idLCUI = charIDToTypeID( "LCUI" );
        desc635.putInteger( idLCUI, 100 );
        var idLChT = charIDToTypeID( "LChT" );
        desc635.putBoolean( idLChT, false );
        var idLChV = charIDToTypeID( "LChV" );
        desc635.putBoolean( idLChV, false );
        var idTrns = charIDToTypeID( "Trns" );
        desc635.putBoolean( idTrns, true );
        var idMtt = charIDToTypeID( "Mtt " );
        desc635.putBoolean( idMtt, true );
        var idDthr = charIDToTypeID( "Dthr" );
        var idIRDt = charIDToTypeID( "IRDt" );
        var idDfsn = charIDToTypeID( "Dfsn" );
        desc635.putEnumerated( idDthr, idIRDt, idDfsn );
        var idDthA = charIDToTypeID( "DthA" );
        desc635.putInteger( idDthA, 100 );
        var idMttR = charIDToTypeID( "MttR" );
        desc635.putInteger( idMttR, 255 );
        var idMttG = charIDToTypeID( "MttG" );
        desc635.putInteger( idMttG, 255 );
        var idMttB = charIDToTypeID( "MttB" );
        desc635.putInteger( idMttB, 255 );
        var idSHTM = charIDToTypeID( "SHTM" );
        desc635.putBoolean( idSHTM, false );
        var idSImg = charIDToTypeID( "SImg" );
        desc635.putBoolean( idSImg, true );
        var idSWsl = charIDToTypeID( "SWsl" );
        var idSTsl = charIDToTypeID( "STsl" );
        var idSLAl = charIDToTypeID( "SLAl" );
        desc635.putEnumerated( idSWsl, idSTsl, idSLAl );
        var idSWch = charIDToTypeID( "SWch" );
        var idSTch = charIDToTypeID( "STch" );
        var idCHsR = charIDToTypeID( "CHsR" );
        desc635.putEnumerated( idSWch, idSTch, idCHsR );
        var idSWmd = charIDToTypeID( "SWmd" );
        var idSTmd = charIDToTypeID( "STmd" );
        var idMDCC = charIDToTypeID( "MDCC" );
        desc635.putEnumerated( idSWmd, idSTmd, idMDCC );
        var idohXH = charIDToTypeID( "ohXH" );
        desc635.putBoolean( idohXH, false );
        var idohIC = charIDToTypeID( "ohIC" );
        desc635.putBoolean( idohIC, true );
        var idohAA = charIDToTypeID( "ohAA" );
        desc635.putBoolean( idohAA, true );
        var idohQA = charIDToTypeID( "ohQA" );
        desc635.putBoolean( idohQA, true );
        var idohCA = charIDToTypeID( "ohCA" );
        desc635.putBoolean( idohCA, false );
        var idohIZ = charIDToTypeID( "ohIZ" );
        desc635.putBoolean( idohIZ, true );
        var idohTC = charIDToTypeID( "ohTC" );
        var idSToc = charIDToTypeID( "SToc" );
        var idOCzerothree = charIDToTypeID( "OC03" );
        desc635.putEnumerated( idohTC, idSToc, idOCzerothree );
        var idohAC = charIDToTypeID( "ohAC" );
        var idSToc = charIDToTypeID( "SToc" );
        var idOCzerothree = charIDToTypeID( "OC03" );
        desc635.putEnumerated( idohAC, idSToc, idOCzerothree );
        var idohIn = charIDToTypeID( "ohIn" );
        desc635.putInteger( idohIn, -1 );
        var idohLE = charIDToTypeID( "ohLE" );
        var idSTle = charIDToTypeID( "STle" );
        var idLEzerothree = charIDToTypeID( "LE03" );
        desc635.putEnumerated( idohLE, idSTle, idLEzerothree );
        var idohEn = charIDToTypeID( "ohEn" );
        var idSTen = charIDToTypeID( "STen" );
        var idENzerozero = charIDToTypeID( "EN00" );
        desc635.putEnumerated( idohEn, idSTen, idENzerozero );
        var idolCS = charIDToTypeID( "olCS" );
        desc635.putBoolean( idolCS, false );
        var idolEC = charIDToTypeID( "olEC" );
        var idSTst = charIDToTypeID( "STst" );
        var idSTzerozero = charIDToTypeID( "ST00" );
        desc635.putEnumerated( idolEC, idSTst, idSTzerozero );
        var idolWH = charIDToTypeID( "olWH" );
        var idSTwh = charIDToTypeID( "STwh" );
        var idWHzeroone = charIDToTypeID( "WH01" );
        desc635.putEnumerated( idolWH, idSTwh, idWHzeroone );
        var idolSV = charIDToTypeID( "olSV" );
        var idSTsp = charIDToTypeID( "STsp" );
        var idSPzerofour = charIDToTypeID( "SP04" );
        desc635.putEnumerated( idolSV, idSTsp, idSPzerofour );
        var idolSH = charIDToTypeID( "olSH" );
        var idSTsp = charIDToTypeID( "STsp" );
        var idSPzerofour = charIDToTypeID( "SP04" );
        desc635.putEnumerated( idolSH, idSTsp, idSPzerofour );
        var idolNC = charIDToTypeID( "olNC" );
            var list35 = new ActionList();
                var desc636 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCzerozero = charIDToTypeID( "NC00" );
                desc636.putEnumerated( idncTp, idSTnc, idNCzerozero );
            var idSCnc = charIDToTypeID( "SCnc" );
            list35.putObject( idSCnc, desc636 );
                var desc637 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNConenine = charIDToTypeID( "NC19" );
                desc637.putEnumerated( idncTp, idSTnc, idNConenine );
            var idSCnc = charIDToTypeID( "SCnc" );
            list35.putObject( idSCnc, desc637 );
                var desc638 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwoeight = charIDToTypeID( "NC28" );
                desc638.putEnumerated( idncTp, idSTnc, idNCtwoeight );
            var idSCnc = charIDToTypeID( "SCnc" );
            list35.putObject( idSCnc, desc638 );
                var desc639 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc639.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list35.putObject( idSCnc, desc639 );
                var desc640 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc640.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list35.putObject( idSCnc, desc640 );
                var desc641 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc641.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list35.putObject( idSCnc, desc641 );
        desc635.putList( idolNC, list35 );
        var idobIA = charIDToTypeID( "obIA" );
        desc635.putBoolean( idobIA, false );
        var idobIP = charIDToTypeID( "obIP" );
        desc635.putString( idobIP, """""" );
        var idobCS = charIDToTypeID( "obCS" );
        var idSTcs = charIDToTypeID( "STcs" );
        var idCSzeroone = charIDToTypeID( "CS01" );
        desc635.putEnumerated( idobCS, idSTcs, idCSzeroone );
        var idovNC = charIDToTypeID( "ovNC" );
            var list36 = new ActionList();
                var desc642 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCzeroone = charIDToTypeID( "NC01" );
                desc642.putEnumerated( idncTp, idSTnc, idNCzeroone );
            var idSCnc = charIDToTypeID( "SCnc" );
            list36.putObject( idSCnc, desc642 );
                var desc643 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwozero = charIDToTypeID( "NC20" );
                desc643.putEnumerated( idncTp, idSTnc, idNCtwozero );
            var idSCnc = charIDToTypeID( "SCnc" );
            list36.putObject( idSCnc, desc643 );
                var desc644 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCzerotwo = charIDToTypeID( "NC02" );
                desc644.putEnumerated( idncTp, idSTnc, idNCzerotwo );
            var idSCnc = charIDToTypeID( "SCnc" );
            list36.putObject( idSCnc, desc644 );
                var desc645 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNConenine = charIDToTypeID( "NC19" );
                desc645.putEnumerated( idncTp, idSTnc, idNConenine );
            var idSCnc = charIDToTypeID( "SCnc" );
            list36.putObject( idSCnc, desc645 );
                var desc646 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCzerosix = charIDToTypeID( "NC06" );
                desc646.putEnumerated( idncTp, idSTnc, idNCzerosix );
            var idSCnc = charIDToTypeID( "SCnc" );
            list36.putObject( idSCnc, desc646 );
                var desc647 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc647.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list36.putObject( idSCnc, desc647 );
                var desc648 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc648.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list36.putObject( idSCnc, desc648 );
                var desc649 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwofour = charIDToTypeID( "NC24" );
                desc649.putEnumerated( idncTp, idSTnc, idNCtwofour );
            var idSCnc = charIDToTypeID( "SCnc" );
            list36.putObject( idSCnc, desc649 );
                var desc650 = new ActionDescriptor();
                var idncTp = charIDToTypeID( "ncTp" );
                var idSTnc = charIDToTypeID( "STnc" );
                var idNCtwotwo = charIDToTypeID( "NC22" );
                desc650.putEnumerated( idncTp, idSTnc, idNCtwotwo );
            var idSCnc = charIDToTypeID( "SCnc" );
            list36.putObject( idSCnc, desc650 );
        desc635.putList( idovNC, list36 );
        var idovCM = charIDToTypeID( "ovCM" );
        desc635.putBoolean( idovCM, false );
        var idovCW = charIDToTypeID( "ovCW" );
        desc635.putBoolean( idovCW, true );
        var idovCU = charIDToTypeID( "ovCU" );
        desc635.putBoolean( idovCU, true );
        var idovSF = charIDToTypeID( "ovSF" );
        desc635.putBoolean( idovSF, true );
        var idovCB = charIDToTypeID( "ovCB" );
        desc635.putBoolean( idovCB, true );
        var idovSN = charIDToTypeID( "ovSN" );
        desc635.putString( idovSN, """images""" );
    var idSaveForWeb = stringIDToTypeID( "SaveForWeb" );
    desc634.putObject( idUsng, idSaveForWeb, desc635 );
executeAction( idExpr, desc634, DialogModes.NO );
} 

var fileName = "/" + doc.name.replace(/.\w+$/,"") + ".gif";

saveGIF(fileName);

 

But it didn't work as expected. It didn't save my image. 😞

And to be honest, I'm really bad into handling action manager code. 

 

I'm just trying to create this script that save my image as a high quality gif in the same folder as the .psd file and with the same name as the original file.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 28, 2020 Jan 28, 2020

Copy link to clipboard

Copied

Proofreading is important. Your script has both logic and spelling errors in it, fix those first.

 

Annotation 2020-01-28 111655.pngexpand image

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 28, 2020 Jan 28, 2020

Copy link to clipboard

Copied

LATEST

Thanks!

 

Looks like I could solve by using the "GIFSaveOptions" instead of using the "ExportOptionsSaveForWeb" method.

I hope it will work in all files, I've made a few tests here and it worked.

 

The way it worked is like this:

 

 

#target photoshop
app.bringToFront();

var doc = activeDocument;

function saveGIF (fileName){
        
        var myFile = new File(doc.path + "/" + fileName + ".gif")
                
        var gifOptions = new GIFSaveOptions(); 
        
        gifOptions.palette = Palette.LOCALSELECTIVE;
        gifOptions.colors = 256;
        gifOptions.dither = Dither.DIFFUSION;
        gifOptions.ditherAmout = 100;
        gifOptions.forced = ForcedColors.WEB;
        gifOptions.interlaced = true;
        gifOptions.matte = MatteType.WHITE;
        gifOptions.preserveExactColors = true;
        gifOptions.transparency = true;       
        
        doc.saveAs(myFile, gifOptions, true);
    
};

var fileName = doc.name.replace(/.\w+$/,"");

saveGIF(fileName);

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines