This repository was archived by the owner on Jun 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathframer.jstalk
130 lines (100 loc) · 3.56 KB
/
framer.jstalk
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
// framer.jstalk
// Author: Jeremy Mack
// Code Website: TODO
// Company: Pile of Turtles, LLC
// Company Website: http://pileofturtles.com
// Acorn script that opens a target screenshot and applies the iPad frame It
// accepts one argument, which is the location of the PNG file to which it is
// going to add the screenshot.
// Options
var makeThumbnails = true;
var thumbnailWidth = 120;
var suffix = "SS";
var smallSuffix = "_thumb";
var fullFormat = ".jpeg";
var thumbnailFormat = ".png";
var jpegQuality = 90;
// Resource Locations
var iPad2VerticalPSD = "iPad_2_Vt.acorn";
var iPad2HorizontalPSD = "iPad_2_Hz.acorn";
var iPhone4VerticalPSD = "iPhone_4_Vt.acorn";
var iPhone4HorizontalPSD = "iPhone_4_Hz.acorn";
// Constants
var outputFolder = "framed";
// Argument Processing
var pi = NSProcessInfo.processInfo();
var argCount = pi.arguments().count();
var screenshot = null;
var resourcesDirectory = null;
if (pi.arguments().length() > 1) {
screenshot = pi.arguments()[2];
resourcesDirectory = pi.arguments()[3];
}
if (screenshot != null && resourcesDirectory != null) {
// Create output file name
var splitFile = /^(.*)\.(.*)$/.exec(screenshot);
var file = splitFile[1];
var extension = splitFile[2];
var filename = file.split("/").pop();
var directory = file.substring(0, file.lastIndexOf("/")+1);
var outputDirectory = directory + outputFolder;
var outputFile = outputDirectory + "/" + filename + suffix + fullFormat;
var smallOutputFile = outputDirectory + "/" + filename + suffix + smallSuffix + thumbnailFormat;
// Open iPad template
var acorn = JSTalk.application("Acorn");
var tmpDoc = acorn.open(screenshot);
var size = tmpDoc.canvasSize();
tmpDoc.close();
var scaleDown = false;
var doc = null;
switch(size.width) {
case 768:
doc = acorn.open(resourcesDirectory + iPad2VerticalPSD);
break;
case 1024:
doc = acorn.open(resourcesDirectory + iPad2HorizontalPSD);
break;
case 320:
doc = acorn.open(resourcesDirectory + iPhone4VerticalPSD);
break;
case 640:
scaleDown = true;
doc = acorn.open(resourcesDirectory + iPhone4VerticalPSD);
break;
case 480:
doc = acorn.open(resourcesDirectory + iPhone4HorizontalPSD);
break;
case 960:
scaleDown = true;
doc = acorn.open(resourcesDirectory + iPhone4HorizontalPSD);
break;
default:
print("Unsupported width (" + size.width + "px) for " + screenshot);
}
if (doc != null) {
// Insert screenshot behind gloss
var screenshotLayer = doc.baseGroup().insertLayerWithImagePath_atIndex(screenshot, 1);
if (scaleDown) {
// Halve layer dimensions to account for a retina iPhone image
[screenshotLayer scaleXBy:0.5 yBy:0.5];
}
// Center screenshot
var canvasWidth = doc.canvasSize().width;
var canvasHeight = doc.canvasSize().height;
var imageWidth = screenshotLayer.size().width;
var imageHeight = screenshotLayer.size().height;
var newImageX = (canvasWidth - imageWidth) / 2;
var newImageY = (canvasHeight - imageHeight) / 2;
screenshotLayer.setFrameOrigin(NSMakePoint(newImageX, newImageY));
// Export the full size images
doc.webExportWithOptions({'uti': 'public'+fullFormat, 'quality': jpegQuality, 'file': outputFile});
if (makeThumbnails) {
// Scale then export the thumbnails
doc.scaleImageToWidth(thumbnailWidth);
doc.webExportWithOptions({'uti': 'public'+thumbnailFormat, 'file': smallOutputFile});
}
doc.close();
}
} else {
print("Please provide the screenshot and resources directory");
}