Skip to main content
Cyril500
Known Participant
July 22, 2017
Answered

Scripting "save as animated GIF" in Photoshop using Gifsicle to set Loop=forever

  • July 22, 2017
  • 1 reply
  • 4387 views

My script below saves animated .gif file from Photoshop, but with Looping = 1. I need Looping = forever.
There is a program, called Gifsicle  http://www.lcdf.org/gifsicle/

It runs under the command line and does everything with GIF.

In my case, Gifsicle string looks like that:

C://gifsicle.exe --batch --loop=forever −−careful *.gif

Is it possible at all for Photoshop jsx script to run Gifsicle and convert the file on disk AFTER this jsx script saves this file to the disc?

If yes, can anybody help me to integrate the line above into my "saving gif" script below?

#target photoshop

main();

function main(){

if(!documents.length) return;

try{

var Path= activeDocument.path;

}catch(e){var Path = "~/desktop";}

var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');

var layerName = app.activeDocument.activeLayer.name.replace(/[:\/\\*\?\"\<\>\|]/g, "_");

var saveFile= new File(Path + "/" + Name + "-" + layerName + ".gif");

SaveForWeb(saveFile);

}

function SaveForWeb(saveFile) {

var sfwOptions = new ExportOptionsSaveForWeb();

   sfwOptions.format = SaveDocumentType.COMPUSERVEGIF;

   sfwOptions.includeProfile = false;

   sfwOptions.interlaced = 1;

   sfwOptions.optimized = true;

   sfwOptions.transparency = 1;

   sfwOptions.ColorReductionType = ColorReductionType.SELECTIVE;

   sfwOptions.dither = Dither.NONE; 

   sfwOptions.ditherAmount = 80;

   sfwOptions.webSnap = 0;

   sfwOptions.colors = 128;

activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);

}

http://www.lcdf.org/gifsicle/

This topic has been closed for replies.
Correct answer SuperMerlin

If you mean the function below - I tried it. Unfortunately, it still doesn't work for scripts...



Ok, this now works for me in a Browser even without "Loop Playback" being ticked.

gifsicle.exe did not like me specifing just a single filename so I have used *.gif and this seems to work.

#target photoshop;

try{

var Path= activeDocument.path;

}catch(e){var Path = "~/desktop";}

var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');

var layerName = app.activeDocument.activeLayer.name.replace(/[:\/\\*\?\"\<\>\|]/g, "_");

var saveFile= new File(Path + "/" + Name + "-" + layerName + ".gif");

var rex = new RegExp(Name + "-" + layerName + ".gif");

var files = decodeURI(saveFile.fsName).replace(rex,"*.gif");

var cmd = 'C:/tmp/gifsicle.exe --batch --loop=forever −−careful ';

cmd += '\"' + files+ '\"';

SaveForWeb(saveFile);

app.system(cmd);

function SaveForWeb(saveFile) {

var sfwOptions = new ExportOptionsSaveForWeb();

   sfwOptions.format = SaveDocumentType.COMPUSERVEGIF;

   sfwOptions.includeProfile = false;

   sfwOptions.interlaced = 1;

   sfwOptions.optimized = true;

   sfwOptions.transparency = 1;

   sfwOptions.ColorReductionType = ColorReductionType.SELECTIVE;

   sfwOptions.dither = Dither.NONE; 

   sfwOptions.ditherAmount = 80;

   sfwOptions.webSnap = 0;

   sfwOptions.colors = 128;

activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);

};

1 reply

JJMack
Community Expert
Community Expert
July 22, 2017

Why did you start a second thread I posted in you other thread Scriptlistener: scripting save as GIF with loop endless and file name as layer name

JJMack
Cyril500
Cyril500Author
Known Participant
July 23, 2017

Because this post is about solving the problem using Gifslie.

The previous post is solving the problem using Scriptlistener.

These are completely different approaches...

However, I cannot solve the problem using any of them so far...

SuperMerlin
Inspiring
July 23, 2017

This works for me in CS6 and Windows 10.

N.B. I have gifsicle.exe in C:\tmp folder.

#target photoshop;

try{

var Path= activeDocument.path;

}catch(e){var Path = "~/desktop";}

var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');

var layerName = app.activeDocument.activeLayer.name.replace(/[:\/\\*\?\"\<\>\|]/g, "_");

var saveFile= new File(Path + "/" + Name + "-" + layerName + ".gif");

var cmd = 'C:/tmp/gifsicle.exe --batch --loop=forever −−careful ';

cmd += decodeURI(saveFile);

SaveForWeb(saveFile);

app.system(cmd);

function SaveForWeb(saveFile) {

var sfwOptions = new ExportOptionsSaveForWeb();

   sfwOptions.format = SaveDocumentType.COMPUSERVEGIF;

   sfwOptions.includeProfile = false;

   sfwOptions.interlaced = 1;

   sfwOptions.optimized = true;

   sfwOptions.transparency = 1;

   sfwOptions.ColorReductionType = ColorReductionType.SELECTIVE;

   sfwOptions.dither = Dither.NONE; 

   sfwOptions.ditherAmount = 80;

   sfwOptions.webSnap = 0;

   sfwOptions.colors = 128;

activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);

};