I am working on a game that uses an animation software called Spine to create the character animations. Spine allows you to create skeletal animations by attaching PNGs to bones & then moving the bones on a timeline by key-framing position, scale, rotation, etc. For the game graphics to look sharp, we need to make sure each of the PNGs are divisible by a certain number ratio.
So with that in mind, I'm trying to create a PS Script that will export each layer out as a PNG but check for the following:
- If the layer's dimensions are not divisible by 16, add on pixels evenly to the height & width to make the dimensions divisible by 16. Then export as a PNG.
- If the layer's dimensions are already divisible by 16, export out a PNG as normal.
Some kind guys helped me with a piece of code that adds on pixels to a canvas to make it divisible by 16 but I'd like to make the code more dynamic by it looking at layers & bypassing the script if the layer is already divisible by 16:
preferences.rulerUnits = Units.PIXELS; with(activeDocument)
resizeCanvas(width + 16 - width % 16, height + 16 - height % 16)
Any help with this problem would be greatly appreciated, i'm a humble animator and this is way over my head! Kind Regards, Steve.
The code you have will increase a dimension by 16 if it's already divisible by 16, which is pointless. I don't think the "kind guys" did you any favors here.
For each dimension with length
n, change it ton + (-n & 15). That will leavenas is if it is already a multiple of 16.If both dimensions are unchanged by this, then don't bother resizing the image.