Last active
December 16, 2015 08:08
-
-
Save wiledal/5403451 to your computer and use it in GitHub Desktop.
Photoshop script for making a sprite sheet out of a folder of images.
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
/* FUNCS */ | |
function move(l,x,y) { | |
var Position = l.bounds; | |
Position[0] = x - Position[0]; | |
Position[1] = y - Position[1]; | |
l.translate(-Position[0],-Position[1]); | |
} | |
function run() { | |
var folder = Folder.selectDialog("Please select input folder"); | |
var files = folder.getFiles(); | |
app.preferences.rulerUnits = Units.PIXELS; | |
app.preferences.typeUnits = TypeUnits.PIXELS; | |
var cols = prompt("Columns", 10); | |
var colWidth = prompt("Column width", 330); | |
var rowHeight = prompt("Row height", 840); | |
var numRows = Math.ceil(files.length / cols); | |
var outDoc = app.documents.add(colWidth * cols, rowHeight * numRows, 72, "outdoc"); | |
for (var i = 0; i < files.length; i++) { | |
var p = files[i]; | |
open(p); | |
var d = activeDocument; | |
d.trim(); | |
d.selection.selectAll(); | |
d.selection.copy(); | |
d.close(SaveOptions.DONOTSAVECHANGES); | |
app.activeDocument = outDoc; | |
outDoc.paste(); | |
var l = outDoc.activeLayer; | |
var h = l.bounds[3] - l.bounds[1]; | |
var y = Math.floor(i / cols) * rowHeight; | |
var x = i % cols * colWidth; | |
var yoffset = rowHeight - parseInt(h); | |
move(l, x, y + yoffset); | |
} | |
} | |
/* SCRIPT */ | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment