Skip to content
Newer
Older
100644 131 lines (100 sloc) 3.56 KB
dff0d26 First commit
Jeremy Mack authored
1 // framer.jstalk
2
3 // Author: Jeremy Mack
4 // Code Website: TODO
5 // Company: Pile of Turtles, LLC
6 // Company Website: http://pileofturtles.com
7
8 // Acorn script that opens a target screenshot and applies the iPad frame It
9 // accepts one argument, which is the location of the PNG file to which it is
10 // going to add the screenshot.
11
9f2dbf2 Added README
Jeremy Mack authored
12 // Options
3b67964 Now with iPhone support!
Jeremy Mack authored
13 var makeThumbnails = true;
9f2dbf2 Added README
Jeremy Mack authored
14 var thumbnailWidth = 120;
15
16 var suffix = "SS";
17 var smallSuffix = "_thumb";
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
18 var fullFormat = ".jpeg";
19 var thumbnailFormat = ".png";
20
21 var jpegQuality = 90;
22
23 // Resource Locations
24 var iPad2VerticalPSD = "iPad_2_Vt.acorn";
25 var iPad2HorizontalPSD = "iPad_2_Hz.acorn";
26 var iPhone4VerticalPSD = "iPhone_4_Vt.acorn";
27 var iPhone4HorizontalPSD = "iPhone_4_Hz.acorn";
28
29 // Constants
30 var outputFolder = "framed";
9f2dbf2 Added README
Jeremy Mack authored
31
dff0d26 First commit
Jeremy Mack authored
32
9f2dbf2 Added README
Jeremy Mack authored
33 // Argument Processing
dff0d26 First commit
Jeremy Mack authored
34 var pi = NSProcessInfo.processInfo();
35 var argCount = pi.arguments().count();
36
37 var screenshot = null;
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
38 var resourcesDirectory = null;
dff0d26 First commit
Jeremy Mack authored
39
40 if (pi.arguments().length() > 1) {
41 screenshot = pi.arguments()[2];
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
42 resourcesDirectory = pi.arguments()[3];
dff0d26 First commit
Jeremy Mack authored
43 }
44
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
45 if (screenshot != null && resourcesDirectory != null) {
dff0d26 First commit
Jeremy Mack authored
46
47 // Create output file name
48 var splitFile = /^(.*)\.(.*)$/.exec(screenshot);
49 var file = splitFile[1];
50 var extension = splitFile[2];
51 var filename = file.split("/").pop();
52 var directory = file.substring(0, file.lastIndexOf("/")+1);
9f2dbf2 Added README
Jeremy Mack authored
53 var outputDirectory = directory + outputFolder;
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
54 var outputFile = outputDirectory + "/" + filename + suffix + fullFormat;
55 var smallOutputFile = outputDirectory + "/" + filename + suffix + smallSuffix + thumbnailFormat;
dff0d26 First commit
Jeremy Mack authored
56
57 // Open iPad template
58 var acorn = JSTalk.application("Acorn");
59
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
60
61 var tmpDoc = acorn.open(screenshot);
62 var size = tmpDoc.canvasSize();
63 tmpDoc.close();
64
65
3b67964 Now with iPhone support!
Jeremy Mack authored
66 var scaleDown = false;
67
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
68 var doc = null;
69 switch(size.width) {
70 case 768:
71 doc = acorn.open(resourcesDirectory + iPad2VerticalPSD);
72 break;
73 case 1024:
74 doc = acorn.open(resourcesDirectory + iPad2HorizontalPSD);
75 break;
3b67964 Now with iPhone support!
Jeremy Mack authored
76 case 320:
77 doc = acorn.open(resourcesDirectory + iPhone4VerticalPSD);
78 break;
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
79 case 640:
3b67964 Now with iPhone support!
Jeremy Mack authored
80 scaleDown = true;
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
81 doc = acorn.open(resourcesDirectory + iPhone4VerticalPSD);
82 break;
3b67964 Now with iPhone support!
Jeremy Mack authored
83 case 480:
84 doc = acorn.open(resourcesDirectory + iPhone4HorizontalPSD);
85 break;
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
86 case 960:
3b67964 Now with iPhone support!
Jeremy Mack authored
87 scaleDown = true;
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
88 doc = acorn.open(resourcesDirectory + iPhone4HorizontalPSD);
89 break;
90 default:
3b67964 Now with iPhone support!
Jeremy Mack authored
91 print("Unsupported width (" + size.width + "px) for " + screenshot);
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
92 }
93
3b67964 Now with iPhone support!
Jeremy Mack authored
94 if (doc != null) {
95 // Insert screenshot behind gloss
96 var screenshotLayer = doc.baseGroup().insertLayerWithImagePath_atIndex(screenshot, 1);
97
98 if (scaleDown) {
99 // Halve layer dimensions to account for a retina iPhone image
100 [screenshotLayer scaleXBy:0.5 yBy:0.5];
101 }
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
102
3b67964 Now with iPhone support!
Jeremy Mack authored
103 // Center screenshot
104 var canvasWidth = doc.canvasSize().width;
105 var canvasHeight = doc.canvasSize().height;
dff0d26 First commit
Jeremy Mack authored
106
3b67964 Now with iPhone support!
Jeremy Mack authored
107 var imageWidth = screenshotLayer.size().width;
108 var imageHeight = screenshotLayer.size().height;
dff0d26 First commit
Jeremy Mack authored
109
3b67964 Now with iPhone support!
Jeremy Mack authored
110 var newImageX = (canvasWidth - imageWidth) / 2;
111 var newImageY = (canvasHeight - imageHeight) / 2;
dff0d26 First commit
Jeremy Mack authored
112
3b67964 Now with iPhone support!
Jeremy Mack authored
113 screenshotLayer.setFrameOrigin(NSMakePoint(newImageX, newImageY));
dff0d26 First commit
Jeremy Mack authored
114
3b67964 Now with iPhone support!
Jeremy Mack authored
115 // Export the full size images
116 doc.webExportWithOptions({'uti': 'public'+fullFormat, 'quality': jpegQuality, 'file': outputFile});
dff0d26 First commit
Jeremy Mack authored
117
3b67964 Now with iPhone support!
Jeremy Mack authored
118 if (makeThumbnails) {
119 // Scale then export the thumbnails
120 doc.scaleImageToWidth(thumbnailWidth);
121 doc.webExportWithOptions({'uti': 'public'+thumbnailFormat, 'file': smallOutputFile});
122 }
123
124 doc.close();
125 }
dff0d26 First commit
Jeremy Mack authored
126
127 } else {
23b7dd0 Switched to open source iPad 2 images
Jeremy Mack authored
128 print("Please provide the screenshot and resources directory");
dff0d26 First commit
Jeremy Mack authored
129 }
130
Something went wrong with that request. Please try again.