Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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;
numLayers = docRef.artLayers.length;
var cols = docRef.width;
var spriteX = docRef.width;
var spriteY = docRef.height;
// put things in order
app.preferences.rulerUnits = Units.PIXELS;
//Definir tamanho do Canvas
sqrtLayer =Math.sqrt(numLayers);
newXLeng=Math.ceil(sqrtLayer);
newYLeng=Math.ceil(sqrtLayer);
Fit=1;
for (i=0; i < sqrtLayer+1; i++)
{
if((newYLeng*newXLeng)!= numLayers){
newYLeng=newYLeng-1;
Fit=1;
}
else{
Fit=0;
}
}
if(Fit==1){
newYLeng = 1;
alert(newYLeng);
newXLeng = numLayers;
alert(newXLeng);
}
docRef.resizeCanvas( newXLeng*spriteX, newYLeng*spriteY, AnchorPosition.TOPLEFT );
// move the layers around, j representa Y e i representa X
NumeroCamada=0;
for(j=0;j<newYLeng;j++)
{
for (i=0; i < newXLeng; i++)
{
docRef.artLayers[NumeroCamada].visible = 1;
var movX = spriteX*i;
var movY = spriteY *j;
docRef.artLayers[NumeroCamada].translate(movX, movY);
NumeroCamada++;
}
}
}
@eriktx11

This comment has been minimized.

Copy link

eriktx11 commented Dec 30, 2016

Sweet !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.