-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhead_img_generator.jsx
165 lines (143 loc) · 4.73 KB
/
head_img_generator.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//@target illustrator
//@include json2.js
//locate this file in {Username}\\Documents\\Adobe Scripts\\
//return date as yy-mm-dd format
Date.prototype.yymmdd = function() {
var yy = this.getFullYear().toString();
var mm = (this.getMonth() + 1).toString();
var dd = this.getDate().toString();
return yy + "-" + (mm[1] ? mm : '0' + mm[0]) + "-" + (dd[1] ? dd : '0' + dd[0]);
}
//TODO: IDE를 통하지 않고 바로 실행시 작동안됨
//read content from JSON
var path_JSON="~\\Desktop\\LYJ\\11. Blog\\Automation\\nblog_news_posting\\img_content.json";
var content = readJSON(path_JSON);
content.date = (new Date()).yymmdd();
var DEST_MGEN = "C:/Users/MGEN/Desktop/LYJ/11. Blog/Output/";
var DEST_IPF = "C:/Users/MGEN/Desktop/LYJ/00. IPF/Output/";
var TARGET_MGEN = "C:/Users/MGEN/Desktop/LYJ/11. Blog/Template/";
var TARGET_IPF = "C:/Users/MGEN/Desktop/LYJ/00. IPF/new/";
var tempTarget = getTarget(content.type, content.category);
var doc = getTargetFile(tempTarget);
var tempDest = getDest(content.type);
var outPath = getDatePath(tempDest);
var outName = getOutputName();
var outFile = new File(outPath + outName + ".png");
if (doc) createImage(content);
function readJSON(file_path) {
var f = File(file_path);
f.open('r');
var content = f.read();
f.close();
content=JSON.parse(content);
return content;
}
function createImage(content) {
//select item in layer
var layer_content = doc.layers.getByName('Content');
var item_newspaper = layer_content.pageItems.getByName('newspaper');
var item_date = layer_content.pageItems.getByName('date');
var item_headline = layer_content.pageItems.getByName('headline');
//change content
item_newspaper.contents = content.newspaper;
item_date.contents = content.date;
item_headline.contents = content.headline;
//export options
var opt = setOption(300, false, false);
var color = new RGBColor();
color.white = 255;
var activeAB = doc.artboards[doc.artboards.getActiveArtboardIndex()];
//export
doc.imageCapture(outFile, activeAB.artboardRect, opt);
alert("File exported to" + outFile.toString());
}
function getTarget(type, content) {
var targetPath;
var targetName;
if (type == "IPF") {
targetPath = TARGET_IPF;
switch (content) {
case "patent":
targetName = "01_특허";
break;
case "design":
targetName = "02_상표디자인";
break;
case "copyright":
targetName = "03_저작권";
break;
case "ipsuit":
targetName = "04_IP분쟁소송";
break;
case "startup":
targetName = "05_Startup information";
break;
default:
alert("Content type mismatch");
return null;
}
return targetPath + targetName + ".ai/";
} else if (type == "MGEN") {
targetPath = TARGET_MGEN;
switch (content) {
case "blockchain":
targetName = "01_BLOCKCHAIN";
break;
case "smart_factory":
targetName = "02_SMART_FACTORY";
break;
case "3dmet":
targetName = "03_3DMET";
break;
default:
alert("Content type mismatch");
return null;
}
return targetPath + targetName + ".ai/";
} else {
alert("Blog Type mismatch");
return null;
}
}
function getDest(type) {
if (type == "IPF") return DEST_IPF;
else if (type == "MGEN") return DEST_MGEN;
else {
alert("Type mismatch");
return null;
}
}
function setOption(ppi, transparency, matte) {
var options = new ImageCaptureOptions();
options.resolution = ppi;
options.transparency = transparency;
options.matte = matte;
options.antiAliasing = true;
return options;
}
function getTargetFile(target_path) {
var target = new File(target_path);
var doc = app.open(target);
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
if (doc)
return doc;
else {
alert("There is no such file\n");
return null;
}
}
function getDatePath(outpath) {
var date = new Date();
var year = date.getFullYear().toString();
var month = (date.getMonth() + 1).toString();
month = month[1] ? month : '0' + month[0]
return outpath + year + "/" + month + "/";
}
function getOutputName() {
var date = new Date();
var month = (date.getMonth() + 1).toString();
month = month[1] ? month : '0' + month[0]
var day = date.getDate().toString();
day = day[1] ? day : '0' + day[0]
return month + day;
}