Skip to content

Instantly share code, notes, and snippets.

@Arahnoid
Forked from wiledal/PhotoshopSpriteStripMaker.js
Last active April 21, 2019 23:00
Show Gist options
  • Save Arahnoid/213956823f6545201bcc to your computer and use it in GitHub Desktop.
Save Arahnoid/213956823f6545201bcc to your computer and use it in GitHub Desktop.
[Export sprite sheet] Photoshop script for making a sprite sheet out of a folder of images #Photoshop
/* 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