When I play the animation in photoshop, it looks fine. Every layer is in the correct position. When I run my script that saves each group to a png, the results have some layers offset.
I believe layers have weird issues with positions in animations. An image in a layer could have a different position in one frame and not another frame. I believe I’d have to get the script to step the frame in the animation to get the correct position, but I’m not sure how I would do that.
var set;
var layer;
var count = 0;
for(var i = 0; i < app.activeDocument.layerSets.length; i ++)
{
set = app.activeDocument.layerSets[i];
set.visible = false;
count ++;
}
for(var i = 0; i < app.activeDocument.layerSets.length; i ++)
{
set = app.activeDocument.layerSets[i];
set.visible = true;
// save
var fileName = set.name.replace(/[\*/?:"|<> ]/g,'');
if(fileName.length ==0) fileName = "autoname";
var handle = File(app.activeDocument.path + "/" + fileName + ".png");
pngSaveOptions = new PNGSaveOptions();
activeDocument.saveAs(handle, pngSaveOptions, true, Extension.LOWERCASE);
set.visible = false;
}
alert("Saved " + count + " images.");
The correct animation plays in photoshop. The resulting .pngs are incorrect.
https://imgur.com/a/y9PLPUX
2
Answers
Figured it out. This script has a function that can go to another frame in the animation. I use it to render all sub-groups of the animation to their own separate .pngs
If your animation is already in Photoshop timeline, maybe it’s easier just to render the animation to frames? Go to
File > Export > Render Video...
, ChosePhotoshop Image Sequence
as a renderer,PNG
as a format and in Render Options don’t forget to selectStraight
Alpha Channel. This will render all frames to PNGs with transparency.