Created
July 27, 2011 14:07
-
-
Save mattrobenolt/1109430 to your computer and use it in GitHub Desktop.
Crude Photoshop script to import a series of images and lay them out into a sprite sheet.
This file contains hidden or 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
const FRAME_WIDTH = 410; | |
const FRAME_HEIGHT = 280; | |
const MAX_COLUMNS = 10; | |
var newDocumentName = prompt("Name of new document?", "New Sprite Sheet"); | |
var images = getFolder(), | |
background = getBackground(), | |
columns = Math.min(MAX_COLUMNS, images.length), | |
rows = Math.ceil(images.length/MAX_COLUMNS), | |
docRef = app.documents.add(columns*FRAME_WIDTH, rows*FRAME_HEIGHT, 72, newDocumentName, NewDocumentMode.RGB, DocumentFill.TRANSPARENT, 1); | |
var bgDoc = app.open(background); | |
bgDoc.selection.selectAll(); | |
bgDoc.selection.copy(); | |
bgDoc.close(SaveOptions.DONOTSAVECHANGES); | |
var bgLayers = docRef.layerSets.add(); | |
bgLayers.name = "Background"; | |
for(i=0; i<images.length; i++) | |
{ | |
var column = i % MAX_COLUMNS, | |
row = Math.floor(i / MAX_COLUMNS); | |
var h = row*FRAME_HEIGHT, | |
v = column*FRAME_WIDTH; | |
var coord = [ | |
[v, h], | |
[v, h + FRAME_HEIGHT], | |
[v + FRAME_WIDTH, h + FRAME_HEIGHT], | |
[v + FRAME_WIDTH, h], | |
[v, h] | |
]; | |
docRef.selection.select(coord, SelectionType.REPLACE); | |
docRef.paste(); | |
} | |
var fireworksLayers = docRef.layerSets.add(); | |
fireworksLayers.name = "Fireworks"; | |
fireworksLayers.blendMode = BlendMode.LIGHTEN; | |
for(i=0; i<images.length; i++) | |
{ | |
var column = i % MAX_COLUMNS, | |
row = Math.floor(i / MAX_COLUMNS); | |
var imgDoc = app.open(File(images[i])), | |
layerName = imgDoc.name; | |
var solid = new SolidColor(); | |
solid.rgb.red = 0; | |
solid.rgb.green = 0; | |
solid.rgb.blue = 0; | |
var layer = imgDoc.artLayers.add(); | |
imgDoc.selection.selectAll(); | |
imgDoc.selection.fill(solid); | |
imgDoc.layers[0].move(imgDoc.layers[1], ElementPlacement.PLACEAFTER); | |
imgDoc.flatten(); | |
imgDoc.selection.selectAll(); | |
imgDoc.selection.copy(); | |
imgDoc.close(SaveOptions.DONOTSAVECHANGES); | |
var h = row*FRAME_HEIGHT, | |
v = column*FRAME_WIDTH; | |
var coord = [ | |
[v, h], | |
[v, h + FRAME_HEIGHT], | |
[v + FRAME_WIDTH, h + FRAME_HEIGHT], | |
[v + FRAME_WIDTH, h], | |
[v, h] | |
]; | |
docRef.selection.select(coord, SelectionType.REPLACE); | |
docRef.paste(); | |
docRef.activeLayer.name = layerName; | |
} | |
function getBackground(){ | |
var path = "", image; | |
while(true) | |
{ | |
path = prompt("Complete path to source background image:", path); | |
if(path) | |
{ | |
image = new File(path); | |
return image; | |
} | |
alert("Enter a path!"); | |
} | |
} | |
function getFolder(){ | |
var folder, path = "", images; | |
while(true) | |
{ | |
path = prompt("Complete path to folder holding images:", path); | |
if(path) | |
{ | |
folder = new Folder(path); | |
images = folder.getFiles("*.png"); | |
if(images.length > 0) | |
{ | |
images.sort(); | |
return images; | |
} | |
} | |
alert("No images found."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment