Created
January 11, 2016 20:09
-
-
Save Jaytt/6a87a94954ad81e41ca3 to your computer and use it in GitHub Desktop.
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
// 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++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sweet !