This repository has been archived by the owner on Jun 9, 2018. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Framer/framer.jstalk
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
130 lines (100 sloc)
3.56 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); | |
} | |