Highlighted

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

Explorer ,
Jul 22, 2017

Copy link to clipboard

Copied

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/

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

};

TOPICS
Actions and scripting

Views

1.8K

Likes

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

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

Explorer ,
Jul 22, 2017

Copy link to clipboard

Copied

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/

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

};

TOPICS
Actions and scripting

Views

1.8K

Likes

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
Jul 22, 2017 0
Most Valuable Participant ,
Jul 22, 2017

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jul 22, 2017 0
Explorer ,
Jul 23, 2017

Copy link to clipboard

Copied

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...

Likes

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
Reply
Loading...
Jul 23, 2017 0
Guide ,
Jul 23, 2017

Copy link to clipboard

Copied

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

};

Likes

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
Reply
Loading...
Jul 23, 2017 2
Explorer ,
Jul 23, 2017

Copy link to clipboard

Copied

Unfortunately, its result is gif that loops once...


If you would use - apparently - from the command line
"c:\gifsicle.exe --batch --loop=forever −−careful c:\*.gif"

it would convert to gif that loops forever.

But not from the script...

Likes

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
Reply
Loading...
Jul 23, 2017 0
Most Valuable Participant ,
Jul 23, 2017

Copy link to clipboard

Copied

I think you may have a problem with you machine looping animated gif files.  Did any of the GIF of yours I posted loop on you machine?  Can you open a gif that does not loop on you machind  in Photoshop set forever in the frame animation timeline and save a gif that does loop on your machine.  SuperM and Myself have no problem saving animated gif on our machine that loop iusing CS6 and CC 2017. You keep reporting the GIF do not loop?????

JJMack

Likes

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
Reply
Loading...
Jul 23, 2017 0
Guide ,
Jul 24, 2017

Copy link to clipboard

Copied

You are correct, I was just clicking on the gif file and the default viewer does show forever.

BUT if I drag the file to a browser then it only shows once.

I will see if I can get the syntax correct.

I can get it to save manually from Photoshop so that it does forever but not by script.

In the mean time could you try to created an action to select "Loop Playback" using "insert menu item" from the action palette fly out menu. On CS6 it does try and list it but does not record it in the action, maybe it has been fixed in the latest version?

Likes

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
Reply
Loading...
Jul 24, 2017 2
Explorer ,
Jul 24, 2017

Copy link to clipboard

Copied

It is no problem for me to convert manually gif that loops once to gif that loops forever.
Or, to convert such a gif using gifsclie command string.
Your scripts (as well as my initial script) work fine for me and they do produce the animated gif file BUT animation loops just once.

HERE PLEASE ATTENTION: When playing on a machine those files loop FOREVER in VIEWERS such as FSViewer or ACDsee.  BUT when you send it to a server (publish on website) they loop ONCE.

To verify looping - put the CREATED gif FROM the disc into Photoshop AGAIN. What you get is this:

Loop ONCE.

2017-07-23_18-07-39.jpg

Likes

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
Reply
Loading...
Jul 24, 2017 0
Explorer ,
Jul 24, 2017

Copy link to clipboard

Copied

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


lp.jpg

Likes

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
Reply
Loading...
Jul 24, 2017 0
Guide ,
Jul 24, 2017

Copy link to clipboard

Copied

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

};

Likes

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
Reply
Loading...
Jul 24, 2017 2
Explorer ,
Jul 24, 2017

Copy link to clipboard

Copied

SuperMerlin - THANK YOU SOOOOOOOOOOOOOOOOOOOOOOOOOOO MUUUCH!!!!!!!!!!!!!!!!!!!!!!!!! IT WORKS!!!!!!!!!!!!!!!!!!!!!!!!!!!

Likes

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
Reply
Loading...
Jul 24, 2017 0
Most Valuable Participant ,
Jul 24, 2017

Copy link to clipboard

Copied

Good to hear...

JJMack

Likes

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
Reply
Loading...
Jul 24, 2017 1
Cyril500 LATEST
Explorer ,
Jul 24, 2017

Copy link to clipboard

Copied

Thank you JJMack!!! I am sorry, it was my fault - I was not quite clear describing the situation in the beginning of discussion...

Likes

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
Reply
Loading...
Jul 24, 2017 0