Skip to content

Instantly share code, notes, and snippets.

@billpull
Forked from jessefreeman/layers_to_sprite_sheet.js
Last active August 29, 2015 14:02
Show Gist options
  • Save billpull/e3ca1f659b9eef7cab6b to your computer and use it in GitHub Desktop.
Save billpull/e3ca1f659b9eef7cab6b to your computer and use it in GitHub Desktop.
Create vertical sprite in photoshop
// Put this file in Program Files\Adobe\Photoshop\Presets\Scripts\
// In PhotoShop menu File > Automate > Scripts: layersToSprite.js
// Arrange layers into a sprite sheet.
if (documents.length > 0)
{
// --------------------------
docRef = activeDocument;
var activeLayer = docRef.activeLayer;
var padding = 20;
numLayers = docRef.artLayers.length;
var spriteY = docRef.height;
// put things in order
app.preferences.rulerUnits = Units.PIXELS;
// resize the canvas
newY = numLayers * spriteY + padding * 2;
newX = docRef.width + padding;
docRef.resizeCanvas( newX, newY, AnchorPosition.TOPLEFT );
// move the layers around
for (i=0; i < numLayers; i++)
{
docRef.artLayers[i].visible = 1;
var movY = spriteY*i;
docRef.artLayers[i].translate(0, movY);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment