-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrollCropExport.psjs
62 lines (52 loc) · 1.78 KB
/
scrollCropExport.psjs
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
// CHECK OUT THE EXPORT > ARTBOARD TO FILES CODE IF AVAILABLE
// "C:\Program Files\Adobe\Adobe Photoshop (Beta)\Presets\Scripts\ArtBoards To Files.jsx"
// "C:\Program Files\Adobe\Adobe Photoshop (Beta)\Presets\Scripts\ArtboardExport.inc"
const {app, constants} = require('photoshop');
const ufs = require('uxp').storage.localFileSystem;
const domains = require('uxp').storage.domains;
app.preferences.unitsAndRulers.rulerUnits = constants.RulerUnits.PIXELS;
const sourceDoc = app.activeDocument;
const dir = path.dirname(sourceDoc.path);
let cell_width = 1080;
let cell_height = 1350;
let prefix = "prefix";
let n = Math.floor(sourceDoc.width / cell_width);
let mergedDoc = await sourceDoc.duplicate();
await mergedDoc.mergeVisibleLayers();
let doc_crop_array = [];
for(i = 0; i < n; i++){
newDoc = await mergedDoc.duplicate();
cropBounds = {left: i*cell_width, top: 0, right: (i+1)*cell_width, bottom: cell_height};
doc_crop_pair = {
doc: newDoc,
bounds: cropBounds
}
doc_crop_array.push(doc_crop_pair);
}
mergedDoc.closeWithoutSaving();
let file_entries = []
for(i = 0; i < doc_crop_array.length; i++){
let filename = prefix+'_'+(i+1)+'.jpg';
console.log(filename);
try {
let file_i = await ufs.getFileForSaving(filename);
file_entries.push(file_i);
} catch (e) {
console.log(e);
}
}
for(i = 0; i < doc_crop_array.length; i++){
let doc_crop_pair = doc_crop_array[i];
let doc = doc_crop_pair.doc;
let bounds = doc_crop_pair.bounds;
try {
doc.crop(bounds);
doc.saveAs.jpg(file_entries[i], {quality: 12, embedColorProfile: true}, true);
} catch (e) {
console.log(e);
}
}
for(i = 0; i < doc_crop_array.length; i++){
let doc = doc_crop_array[i].doc;
doc.closeWithoutSaving();
}