#target photoshop
var win = new Window("dialog", "序列图转GIF—小彭友[email protected]"); // bounds = [left, top, right, bottom]
win.btnPanel = win.add("panel", [25,10,335,100+30+28], "序列图转GIF");
win.btnPanel.add("statictext", [10, 20, 320, 35], "序列图路径");
InputPath_ed = win.btnPanel.add("edittext", [75, 20, 245, 38], "");
SelectPath_bt = win.btnPanel.add("button", [250, 18, 300, 38], "选择...");
var aa = 25;
win.btnPanel.add("statictext", [10, 20+aa, 320, 35+aa], "输出图路径");
OutputPath_ed = win.btnPanel.add("edittext", [75, 20+aa, 245, 38+aa], "");
SelectFile_bt = win.btnPanel.add("button", [250, 18+aa, 300, 38+aa], "选择...");
win.btnPanel.add("statictext", [10, 20+aa+28, 320, 35+aa+28], "帧延迟时间(0.0-240.0)");
AnimationFrameTime_ed = win.btnPanel.add("edittext", [75+70, 20+aa+28, 245, 38+aa+28], 0.5);
StartRun_bt = win.btnPanel.add("button", [5, 18+aa+28+28, 300, 38+aa+28+5+28], "开始输出");
SelectPath_bt.onClick = function()
{
var sourceFolder = Folder(InputPath_ed.text);
var selectPath = sourceFolder.selectDlg("请选择导入的序列所在文件夹");
if (!selectPath)
{
return;
}
if (Folder(selectPath).exists)
{
InputPath_ed.text = Folder(selectPath).fsName;
}
};
SelectFile_bt.onClick = function()
{
var OutputPath = File.saveDialog("请指定输出GIF文件的路径","gif:*.gif;*.GIF;All files:*.*",false);
if (!OutputPath)
{
return;
}
if (File(OutputPath).exists)
{
var win1 = new Window("dialog", "提示框",[100,100,380,245]);
win1.btnPanel = win1.add("panel", [25,15,255,130], "提示框");
win1.btnPanel.add("statictext", [15,65-40,105+100,85-40], "检测到已经存在该文件");
win1.btnPanel.okBtn = win1.btnPanel.add("button", [15,65,105,85], "覆盖");
win1.btnPanel.cancelBtn = win1.btnPanel.add("button", [120, 65, 210, 85], "取消");
win1.btnPanel.okBtn.onClick = function()
{
win1.close();
OutputPath_ed.text = File(OutputPath).fsName;
};
win1.btnPanel.cancelBtn.onClick = function()
{
win1.close();
};
win1.center();
win1.show();
}
else
{
if (File(OutputPath).parent.exists)
{
OutputPath_ed.text = File(OutputPath).fsName;
}
}
};
StartRun_bt.onClick = function()
{
if (Folder(InputPath_ed.text).exists == false)
{
alert("请检查输入的序列图路径");
return;
}
if (File(OutputPath_ed.text).parent.exists == false)
{
alert("请检查GIF保存路径");
return;
}
var sourceFolder = Folder(InputPath_ed.text);
var seq_file = sourceFolder.getFiles();
ImportAndCreateNewDocument(seq_file[0]);
// 导入
for (var i = 1;i < seq_file.length; i++)
{
try
{
Import(seq_file[i]);
}
catch(err)
{
}
}
// 设置动画帧
for (var j = 0; j < app.activeDocument.layers.length; j++)
{
if (j != 0)
{
//除第一帧,每个图层创建一个动画帧
CreateFrame();
}
// 选中帧
SelectFrame(j + 1);
// 设置帧显示的时间
SetSelectFrameTime(AnimationFrameTime_ed.text);//0.00-240.00
// alert(app.activeDocument.layers[app.activeDocument.layers.length-j-1].name);
// 设置当前选中的帧显示的图层
for (var i = 0; i < app.activeDocument.layers.length; i++)
{
if (app.activeDocument.layers.length-j-1 == i)
{
app.activeDocument.layers[i].visible = true;
}
else
{
app.activeDocument.layers[i].visible = false;
}
}
}
// 保存输出
SaveGif(OutputPath_ed.text);
alert("保存成功");
};
win.center();
win.show();
function SaveGif(GifFilePath)
{
var GifFilePathObject = File(GifFilePath);
FolderPath = GifFilePathObject.path;
FileFullName = GifFilePathObject.name;
// =======================================================
var idExpr = charIDToTypeID( "Expr" );
var desc270 = new ActionDescriptor();
var idUsng = charIDToTypeID( "Usng" );
var desc271 = new ActionDescriptor();
var idOp = charIDToTypeID( "Op " );
var idSWOp = charIDToTypeID( "SWOp" );
var idOpSa = charIDToTypeID( "OpSa" );
desc271.putEnumerated( idOp, idSWOp, idOpSa );
var idDIDr = charIDToTypeID( "DIDr" );
desc271.putBoolean( idDIDr, true );
var idIn = charIDToTypeID( "In " );
desc271.putPath( idIn, new File( FolderPath ) );
var idovFN = charIDToTypeID( "ovFN" );
desc271.putString( idovFN, FileFullName );
var idFmt = charIDToTypeID( "Fmt " );
var idIRFm = charIDToTypeID( "IRFm" );
var idGIFf = charIDToTypeID( "GIFf" );
desc271.putEnumerated( idFmt, idIRFm, idGIFf );
var idIntr = charIDToTypeID( "Intr" );
desc271.putBoolean( idIntr, false );
var idRedA = charIDToTypeID( "RedA" );
var idIRRd = charIDToTypeID( "IRRd" );
var idSltv = charIDToTypeID( "Sltv" );
desc271.putEnumerated( idRedA, idIRRd, idSltv );
var idRChT = charIDToTypeID( "RChT" );
desc271.putBoolean( idRChT, false );
var idRChV = charIDToTypeID( "RChV" );
desc271.putBoolean( idRChV, false );
var idAuRd = charIDToTypeID( "AuRd" );
desc271.putBoolean( idAuRd, false );
var idNCol = charIDToTypeID( "NCol" );
desc271.putInteger( idNCol, 256 );
var idDthr = charIDToTypeID( "Dthr" );
var idIRDt = charIDToTypeID( "IRDt" );
var idDfsn = charIDToTypeID( "Dfsn" );
desc271.putEnumerated( idDthr, idIRDt, idDfsn );
var idDthA = charIDToTypeID( "DthA" );
desc271.putInteger( idDthA, 100 );
var idDChS = charIDToTypeID( "DChS" );
desc271.putInteger( idDChS, 0 );
var idDCUI = charIDToTypeID( "DCUI" );
desc271.putInteger( idDCUI, 0 );
var idDChT = charIDToTypeID( "DChT" );
desc271.putBoolean( idDChT, false );
var idDChV = charIDToTypeID( "DChV" );
desc271.putBoolean( idDChV, false );
var idWebS = charIDToTypeID( "WebS" );
desc271.putInteger( idWebS, 0 );
var idTDth = charIDToTypeID( "TDth" );
var idIRDt = charIDToTypeID( "IRDt" );
var idNone = charIDToTypeID( "None" );
desc271.putEnumerated( idTDth, idIRDt, idNone );
var idTDtA = charIDToTypeID( "TDtA" );
desc271.putInteger( idTDtA, 100 );
var idLoss = charIDToTypeID( "Loss" );
desc271.putInteger( idLoss, 0 );
var idLChS = charIDToTypeID( "LChS" );
desc271.putInteger( idLChS, 0 );
var idLCUI = charIDToTypeID( "LCUI" );
desc271.putInteger( idLCUI, 100 );
var idLChT = charIDToTypeID( "LChT" );
desc271.putBoolean( idLChT, false );
var idLChV = charIDToTypeID( "LChV" );
desc271.putBoolean( idLChV, false );
var idTrns = charIDToTypeID( "Trns" );
desc271.putBoolean( idTrns, true );
var idMtt = charIDToTypeID( "Mtt " );
desc271.putBoolean( idMtt, true );
var idMttR = charIDToTypeID( "MttR" );
desc271.putInteger( idMttR, 255 );
var idMttG = charIDToTypeID( "MttG" );
desc271.putInteger( idMttG, 255 );
var idMttB = charIDToTypeID( "MttB" );
desc271.putInteger( idMttB, 255 );
var idSHTM = charIDToTypeID( "SHTM" );
desc271.putBoolean( idSHTM, false );
var idSImg = charIDToTypeID( "SImg" );
desc271.putBoolean( idSImg, true );
var idSWsl = charIDToTypeID( "SWsl" );
var idSTsl = charIDToTypeID( "STsl" );
var idSLAl = charIDToTypeID( "SLAl" );
desc271.putEnumerated( idSWsl, idSTsl, idSLAl );
var idSWch = charIDToTypeID( "SWch" );
var idSTch = charIDToTypeID( "STch" );
var idCHsR = charIDToTypeID( "CHsR" );
desc271.putEnumerated( idSWch, idSTch, idCHsR );
var idSWmd = charIDToTypeID( "SWmd" );
var idSTmd = charIDToTypeID( "STmd" );
var idMDCC = charIDToTypeID( "MDCC" );
desc271.putEnumerated( idSWmd, idSTmd, idMDCC );
var idohXH = charIDToTypeID( "ohXH" );
desc271.putBoolean( idohXH, false );
var idohIC = charIDToTypeID( "ohIC" );
desc271.putBoolean( idohIC, true );
var idohAA = charIDToTypeID( "ohAA" );
desc271.putBoolean( idohAA, true );
var idohQA = charIDToTypeID( "ohQA" );
desc271.putBoolean( idohQA, true );
var idohCA = charIDToTypeID( "ohCA" );
desc271.putBoolean( idohCA, false );
var idohIZ = charIDToTypeID( "ohIZ" );
desc271.putBoolean( idohIZ, true );
var idohTC = charIDToTypeID( "ohTC" );
var idSToc = charIDToTypeID( "SToc" );
var idOCzerothree = charIDToTypeID( "OC03" );
desc271.putEnumerated( idohTC, idSToc, idOCzerothree );
var idohAC = charIDToTypeID( "ohAC" );
var idSToc = charIDToTypeID( "SToc" );
var idOCzerothree = charIDToTypeID( "OC03" );
desc271.putEnumerated( idohAC, idSToc, idOCzerothree );
var idohIn = charIDToTypeID( "ohIn" );
desc271.putInteger( idohIn, -1 );
var idohLE = charIDToTypeID( "ohLE" );
var idSTle = charIDToTypeID( "STle" );
var idLEzerothree = charIDToTypeID( "LE03" );
desc271.putEnumerated( idohLE, idSTle, idLEzerothree );
var idohEn = charIDToTypeID( "ohEn" );
var idSTen = charIDToTypeID( "STen" );
var idENzerozero = charIDToTypeID( "EN00" );
desc271.putEnumerated( idohEn, idSTen, idENzerozero );
var idolCS = charIDToTypeID( "olCS" );
desc271.putBoolean( idolCS, false );
var idolEC = charIDToTypeID( "olEC" );
var idSTst = charIDToTypeID( "STst" );
var idSTzerozero = charIDToTypeID( "ST00" );
desc271.putEnumerated( idolEC, idSTst, idSTzerozero );
var idolWH = charIDToTypeID( "olWH" );
var idSTwh = charIDToTypeID( "STwh" );
var idWHzeroone = charIDToTypeID( "WH01" );
desc271.putEnumerated( idolWH, idSTwh, idWHzeroone );
var idolSV = charIDToTypeID( "olSV" );
var idSTsp = charIDToTypeID( "STsp" );
var idSPzerofour = charIDToTypeID( "SP04" );
desc271.putEnumerated( idolSV, idSTsp, idSPzerofour );
var idolSH = charIDToTypeID( "olSH" );
var idSTsp = charIDToTypeID( "STsp" );
var idSPzerofour = charIDToTypeID( "SP04" );
desc271.putEnumerated( idolSH, idSTsp, idSPzerofour );
var idolNC = charIDToTypeID( "olNC" );
var list47 = new ActionList();
var desc272 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNCzerozero = charIDToTypeID( "NC00" );
desc272.putEnumerated( idncTp, idSTnc, idNCzerozero );
var idSCnc = charIDToTypeID( "SCnc" );
list47.putObject( idSCnc, desc272 );
var desc273 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNConenine = charIDToTypeID( "NC19" );
desc273.putEnumerated( idncTp, idSTnc, idNConenine );
var idSCnc = charIDToTypeID( "SCnc" );
list47.putObject( idSCnc, desc273 );
var desc274 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNCtwoeight = charIDToTypeID( "NC28" );
desc274.putEnumerated( idncTp, idSTnc, idNCtwoeight );
var idSCnc = charIDToTypeID( "SCnc" );
list47.putObject( idSCnc, desc274 );
var desc275 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNCtwofour = charIDToTypeID( "NC24" );
desc275.putEnumerated( idncTp, idSTnc, idNCtwofour );
var idSCnc = charIDToTypeID( "SCnc" );
list47.putObject( idSCnc, desc275 );
var desc276 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNCtwofour = charIDToTypeID( "NC24" );
desc276.putEnumerated( idncTp, idSTnc, idNCtwofour );
var idSCnc = charIDToTypeID( "SCnc" );
list47.putObject( idSCnc, desc276 );
var desc277 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNCtwofour = charIDToTypeID( "NC24" );
desc277.putEnumerated( idncTp, idSTnc, idNCtwofour );
var idSCnc = charIDToTypeID( "SCnc" );
list47.putObject( idSCnc, desc277 );
desc271.putList( idolNC, list47 );
var idobIA = charIDToTypeID( "obIA" );
desc271.putBoolean( idobIA, false );
var idobIP = charIDToTypeID( "obIP" );
desc271.putString( idobIP, """""" );
var idobCS = charIDToTypeID( "obCS" );
var idSTcs = charIDToTypeID( "STcs" );
var idCSzeroone = charIDToTypeID( "CS01" );
desc271.putEnumerated( idobCS, idSTcs, idCSzeroone );
var idovNC = charIDToTypeID( "ovNC" );
var list48 = new ActionList();
var desc278 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNCzeroone = charIDToTypeID( "NC01" );
desc278.putEnumerated( idncTp, idSTnc, idNCzeroone );
var idSCnc = charIDToTypeID( "SCnc" );
list48.putObject( idSCnc, desc278 );
var desc279 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNCtwozero = charIDToTypeID( "NC20" );
desc279.putEnumerated( idncTp, idSTnc, idNCtwozero );
var idSCnc = charIDToTypeID( "SCnc" );
list48.putObject( idSCnc, desc279 );
var desc280 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNCzerotwo = charIDToTypeID( "NC02" );
desc280.putEnumerated( idncTp, idSTnc, idNCzerotwo );
var idSCnc = charIDToTypeID( "SCnc" );
list48.putObject( idSCnc, desc280 );
var desc281 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNConenine = charIDToTypeID( "NC19" );
desc281.putEnumerated( idncTp, idSTnc, idNConenine );
var idSCnc = charIDToTypeID( "SCnc" );
list48.putObject( idSCnc, desc281 );
var desc282 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNCzerosix = charIDToTypeID( "NC06" );
desc282.putEnumerated( idncTp, idSTnc, idNCzerosix );
var idSCnc = charIDToTypeID( "SCnc" );
list48.putObject( idSCnc, desc282 );
var desc283 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNCtwofour = charIDToTypeID( "NC24" );
desc283.putEnumerated( idncTp, idSTnc, idNCtwofour );
var idSCnc = charIDToTypeID( "SCnc" );
list48.putObject( idSCnc, desc283 );
var desc284 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNCtwofour = charIDToTypeID( "NC24" );
desc284.putEnumerated( idncTp, idSTnc, idNCtwofour );
var idSCnc = charIDToTypeID( "SCnc" );
list48.putObject( idSCnc, desc284 );
var desc285 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNCtwofour = charIDToTypeID( "NC24" );
desc285.putEnumerated( idncTp, idSTnc, idNCtwofour );
var idSCnc = charIDToTypeID( "SCnc" );
list48.putObject( idSCnc, desc285 );
var desc286 = new ActionDescriptor();
var idncTp = charIDToTypeID( "ncTp" );
var idSTnc = charIDToTypeID( "STnc" );
var idNCtwotwo = charIDToTypeID( "NC22" );
desc286.putEnumerated( idncTp, idSTnc, idNCtwotwo );
var idSCnc = charIDToTypeID( "SCnc" );
list48.putObject( idSCnc, desc286 );
desc271.putList( idovNC, list48 );
var idovCM = charIDToTypeID( "ovCM" );
desc271.putBoolean( idovCM, false );
var idovCW = charIDToTypeID( "ovCW" );
desc271.putBoolean( idovCW, true );
var idovCU = charIDToTypeID( "ovCU" );
desc271.putBoolean( idovCU, true );
var idovSF = charIDToTypeID( "ovSF" );
desc271.putBoolean( idovSF, true );
var idovCB = charIDToTypeID( "ovCB" );
desc271.putBoolean( idovCB, true );
var idovSN = charIDToTypeID( "ovSN" );
desc271.putString( idovSN, """images""" );
var idSaveForWeb = stringIDToTypeID( "SaveForWeb" );
desc270.putObject( idUsng, idSaveForWeb, desc271 );
executeAction( idExpr, desc270, DialogModes.NO );
}
function SetSelectFrameTime(Time)//单位秒
{
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc266 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref155 = new ActionReference();
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref155.putEnumerated( idanimationFrameClass, idOrdn, idTrgt );
desc266.putReference( idnull, ref155 );
var idT = charIDToTypeID( "T " );
var desc267 = new ActionDescriptor();
var idanimationFrameDelay = stringIDToTypeID( "animationFrameDelay" );
desc267.putDouble( idanimationFrameDelay, Time );
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
desc266.putObject( idT, idanimationFrameClass, desc267 );
executeAction( idsetd, desc266, DialogModes.NO );
}
function HideLayer(LayerName)
{
var idHd = charIDToTypeID( "Hd " );
var desc174 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var list41 = new ActionList();
var ref119 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
ref119.putName( idLyr, LayerName );
list41.putReference( ref119 );
desc174.putList( idnull, list41 );
executeAction( idHd, desc174, DialogModes.NO );
}
function SelectFrame(Index)
{
// =======================================================
var idslct = charIDToTypeID( "slct" );
var desc171 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref117 = new ActionReference();
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
ref117.putIndex( idanimationFrameClass, Index );
desc171.putReference( idnull, ref117 );
executeAction( idslct, desc171, DialogModes.NO );
}
function CreateFrame()
{
// =======================================================
var idDplc = charIDToTypeID( "Dplc" );
var desc169 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref116 = new ActionReference();
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref116.putEnumerated( idanimationFrameClass, idOrdn, idTrgt );
desc169.putReference( idnull, ref116 );
executeAction( idDplc, desc169, DialogModes.NO );
}
function ImportAndCreateNewDocument(FilePath)
{
// =======================================================
var idOpn = charIDToTypeID( "Opn " );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc3.putPath( idnull, new File( FilePath ) );
executeAction( idOpn, desc3, DialogModes.NO );
}
function Import(FilePath)
{
// =======================================================
var idPlc = charIDToTypeID( "Plc " );
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc4.putPath( idnull, new File( FilePath ) );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc4.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc5 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idHrzn, idPxl, 0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idVrtc, idPxl, 0.000000 );
var idOfst = charIDToTypeID( "Ofst" );
desc4.putObject( idOfst, idOfst, desc5 );
executeAction( idPlc, desc4, DialogModes.NO );
}