-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateGIFs.jsx
80 lines (66 loc) · 2.13 KB
/
generateGIFs.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include includes/json2.js
if (!Object.keys) {
#include includes/objectKeysPolyfill.js
}
// Configuration
var emojiNamePrefix = "glitter-";
// Main Function
(function main() {
// Get Document Information
var frameGroup = app.activeDocument.layerSets.getByName("frames");
var symbols = loadJSON("symbols.json");
var symbolKeys = Object.keys(symbols);
// Optionally get color
var textColor = getColorpickerColor();
if (textColor !== false) {
for(var j = 0; j < frameGroup.layers.length; j++) {
var frame = frameGroup.layers[j];
frame.textItem.color = textColor;
}
}
// For each symbol
for(var i = 0; i < symbolKeys.length; i++) {
var key = symbolKeys[i];
var symbol = symbols[key];
// For each GIF frame
for(var j = 0; j < frameGroup.layers.length; j++) {
var frame = frameGroup.layers[j];
frame.textItem.contents = symbol;
};
// Export GIF
SaveGIF('output', emojiNamePrefix + key);
}
if (app.activeDocument != null) {
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
alert('Operation complete!');
})();
function getColorpickerColor() {
if (app.showColorPicker()) {
return app.foregroundColor;
}
else {
return false;
}
};
function SaveGIF(outputFolderName, fileName) {
var doc = app.activeDocument;
var docPath = activeDocument.path.fullName;
// Output Configuration
var sfw = new ExportOptionsSaveForWeb();
sfw.format = SaveDocumentType.COMPUSERVEGIF;
sfw.transparency = true;
// Check if output directory exist, if not create it
var file = new File(docPath+"/"+outputFolderName+"/"+fileName+'.gif');
var outputFolder = Folder(docPath+"/"+outputFolderName);
if(!outputFolder.exists) outputFolder.create();
doc.exportDocument(file, ExportType.SAVEFORWEB, sfw)
};
function loadJSON(relPath) {
var script = new File($.fileName);
var jsonFile = new File(script.path + '/' + relPath);
jsonFile.open('r');
var str = jsonFile.read();
jsonFile.close();
return JSON.parse(str);
};