首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.jpgs插件vs Photoshop gif:从包含一系列gif的文件夹中制作动画gif

.jpgs插件vs Photoshop gif:从包含一系列gif的文件夹中制作动画gif
EN

Stack Overflow用户
提问于 2015-07-15 22:50:14
回答 2查看 141关注 0票数 0

客户给了我一个FTP访问,在那里他上传了15张图片(按顺序编号)每个产品。

问题1:有没有人知道Wordpress中有没有可能生成动画gif或通过插件?

问题2:如果没有这样的插件,我将不得不在Photoshop中创建动画gif。我尝试将脚本“加载文件到堆栈”,然后运行一个操作的组合,但这仍然是非常手动的工作。我不熟悉脚本,但也许有人已经用脚本做过类似的工作?

谢谢,米里亚姆

EN

回答 2

Stack Overflow用户

发布于 2015-07-16 05:43:09

您可以在命令行中使用ImageMagick自动完成此操作,而不需要Photoshop。ImageMagick已经安装在大多数Linux发行版上,并且可以在OSX (最好是通过homebrew )和Windows上使用。

假设你的客户给了你以下37帧,这里所有的画面都被安排成一个大的蒙太奇:

然后,您可以将它们一起放入一个动画GIF中,在命令行中,两帧之间有10厘米的延迟,如下所示:

代码语言:javascript
复制
convert -delay 10 frame* result.gif

要获得以下信息:

票数 1
EN

Stack Overflow用户

发布于 2015-07-16 21:17:08

jpgYup,使用ImageMagick会更简单--下面的脚本就行了。我已经为每个帧的持续时间添加了一秒,可以在脚本的optionals部分中调整,就在顶部。该脚本还必须保存出来的PSD创建,然后使用保存为web创建的动画gif。

在这里,ImageMagic是您的明确选择。

代码语言:javascript
复制
// ******************************************************
//
// LOAD IMAGES (jpg) AS ANIMATED GIF
// ******************************************************

// *** MUST HAVE ANIMATION WINDOW OPEN
// *** SCRIPT WON'T WORK OTHERWISE!

//OPTIONALS
var frameTime = 1.0;
var tempName = "temp"; // file name for psd

//pref pixels
app.preferences.rulerUnits = Units.PIXELS;

var baseDocCreated = false;
var baseImage = "";


var inFolder = Folder.selectDialog("Please select folder to process");
if (inFolder != null)
{
  var fileList = inFolder.getFiles(/\.(jpg)$/i);
}

var exportpath = inFolder;
//alert(inFolder)

// main loop starts here
for(var a = 0 ;a < fileList.length; a++)
{
  // load the frames one by one
  var doc = open(fileList[a]);

  var tempImage = app.activeDocument.name
  // alert(tempImage)

  //create the base document to work with
  if (baseDocCreated == false)
  {
    imageW = app.activeDocument.width.value;
    imageH = app.activeDocument.height.value;
    imageRes = 72;
    imageName = "baseDoc";
    createNewDocument(imageW, imageH, imageRes, imageName)
  }


  var moveTo = app.documents.getByName(baseImage);
  var moveFrom = app.documents.getByName(tempImage);
  moveImage(moveTo, moveFrom)

  //close without saving
  app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

  var rename = tempImage.substring(0, tempImage.length -4);
  app.activeDocument.activeLayer.name = rename
  // alert(app.activeDocument.activeLayer.name)
}



// now deal with the creation
// of the animated gif
var myPSD = exportpath + "\\" + tempName + ".psd";

// call the source document
var srcDoc = app.activeDocument;

// remove background layer
var numOfLayers = srcDoc.layers.length;
srcDoc.layers[numOfLayers-1].remove();

// save the psd
psdIt(myPSD);

// get the file path
var filePath = srcDoc.path;

// create animation frames
createAnimationFromLayers();

// set frame timing
setFrameDuration(frameTime);

// save as gif
SaveGifForWeb(filePath);

//close without saving
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);



function createNewDocument(w, h, res, aname)
{
  // alert(w + "\n" + h + "\n" + res + "\n" + aname)
  var docRef = app.documents.add(w, h, res, aname)
  baseImage = "baseDoc"
  baseDocCreated = true;
  srcDoc = app.activeDocument;
}

// FUNCTION psdIt (source doc)
// --------------------------------------------------------
function psdIt (afilePath)
{

  // save out the psd
  var psdFile = new File(afilePath);
  psdSaveOptions = new PhotoshopSaveOptions();
  psdSaveOptions.embedColorProfile = true;
  psdSaveOptions.alphaChannels = true;  
  activeDocument.saveAs(psdFile, psdSaveOptions, false, Extension.LOWERCASE);
}


function moveImage(to, from)
{
  //select the tempImage
  app.activeDocument = from;
  // move from tempImage to the baseImage
  var duplicateLayer = activeDocument.activeLayer.duplicate(to)
}


// function SAVE GIF FOR WEB (path, jpeg quality)
// ----------------------------------------------------------------
function SaveGifForWeb(saveFile)
{
  var gifOptions = new ExportOptionsSaveForWeb();
  gifOptions.format = SaveDocumentType.COMPUSERVEGIF;  
  gifOptions.interlaced = false;
  gifOptions.colourCount = 256; 
  gifOptions.optimized = true;
  gifOptions.typename = "GIF"; 
  activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, gifOptions);
}

function createAnimationFromLayers()
{
  // =======================================================
  var id9070 = stringIDToTypeID( "animationFramesFromLayers" );
  var desc1033 = new ActionDescriptor();
  executeAction( id9070, desc1033, DialogModes.NO );
}


function addFrameTiming(num)
{
  // =======================================================
  var id9576 = charIDToTypeID( "setd" );
  var desc1151 = new ActionDescriptor();
  var id9577 = charIDToTypeID( "null" );
  var ref694 = new ActionReference();
  var id9578 = stringIDToTypeID( "animationFrameClass" );
  var id9579 = charIDToTypeID( "Ordn" );
  var id9580 = charIDToTypeID( "Trgt" );
  ref694.putEnumerated( id9578, id9579, id9580 );
  desc1151.putReference( id9577, ref694 );
  var id9581 = charIDToTypeID( "T   " );
  var desc1152 = new ActionDescriptor();
  var id9582 = stringIDToTypeID( "animationFrameDelay" );
  desc1152.putDouble( id9582, num );
  var id9583 = stringIDToTypeID( "animationFrameClass" );
  desc1151.putObject( id9581, id9583, desc1152 );
  executeAction( id9576, desc1151, DialogModes.NO );
}

function selectAllFrames()
{
  // =======================================================
  var id3 = stringIDToTypeID( "animationSelectAll" );
  var desc2 = new ActionDescriptor();
  executeAction( id3, desc2, DialogModes.NO );
}

function setFrameDuration(num)
{
  selectAllFrames()
  // =======================================================
  var id4 = charIDToTypeID( "setd" );
  var desc3 = new ActionDescriptor();
  var id5 = charIDToTypeID( "null" );
  var ref1 = new ActionReference();
  var id6 = stringIDToTypeID( "animationFrameClass" );
  var id7 = charIDToTypeID( "Ordn" );
  var id8 = charIDToTypeID( "Trgt" );
  ref1.putEnumerated( id6, id7, id8 );
  desc3.putReference( id5, ref1 );
  var id9 = charIDToTypeID( "T   " );
  var desc4 = new ActionDescriptor();
  var id10 = stringIDToTypeID( "animationFrameDelay" );
  desc4.putDouble( id10, num ); //num (duration in seconds)
  var id11 = stringIDToTypeID( "animationFrameClass" );
  desc3.putObject( id9, id11, desc4 );
  executeAction( id4, desc3, DialogModes.NO );
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31433756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档