Error in `readAdditionalLayerInfo` for file written with ag-psd
This is an awesome library, thanks so much!
I'm running into some trouble with files being produced by ag-psd not being valid, not even for being read back with ag-psd.
This file was produced by ag-psd:
However, when trying to load it with ag-psd, I get this exception:
To me it looks like a 1-byte offset, the 8BIM signature is not correctly found – I'm not sure if this is an issue with reading or writing though. The file opens fine in Photoshop, but Photopea complains that "the file is likely damaged".
I'll try to make a repro for how the file was produced, but thought I'd already open an issue in case you might know what's going on.
EDIT: Seems the issue was writing a mask like this – after I commented this part out the generated file became valid/readable again: (and yes, might be an issue on my end to write canvas: {} as empty object, maybe the library could warn me that this is wrong?)
effectsLayer.mask = {
top: maskTop,
left: maskLeft,
bottom: maskBottom,
right: maskRight,
defaultColor: 0,
positionRelativeToLayer: false,
disabled: false,
fromVectorData: false,
userMaskDensity: 1,
userMaskFeather: 0,
vectorMaskDensity: 1,
vectorMaskFeather: 0,
canvas: {}
};
EDIT 2: Not sure if that mask code is actually at fault, still getting the issue.
I released version 28.2.3 with some improvements for handling reading. I'm not sure why the file is broken in Photopea though, it might be error on their part or incorrect writing in ag-psd. Photoshop file format spec is very unclear on some details of the file structure so it's hard to get everything correct.
Thank you! I believe the issue was that when writing with the mask settings I mentioned above, ag-psd produces a broken file that it itself (and other tools) can't read anymore.
Regarding Photopea, I figured out that it is much more strict than Photoshop in its handling of filter parameters like the parameters of dropShadow layers. Photoshop seems to sanitize/use some defaults for missing properties (like, if you leave the choke or noise parameters out), while Photopea then runs into exceptions.
It seems you've written some NaN values in your filter parameters, so that might also be the issue in Photopea.
I checked some more and it seems some generated files from tests, like this one: https://github.com/Agamnentzar/ag-psd/blob/master/test/write/circle/expected.psd are failing to open in Photopea, but are successfully opening in Photoshop, Paint Tool SAI and Clip Studio Paint as well as showing correct preview on github
When I made Photopea, the only available PSD files were files from Adobe Photoshop. Photoshop adds the "enab" attribute to every layer style. The "DrSh" style must have the "TrnS" attribute, and so on. Photopea does not expect any of these attributes to be missing.
If you craete PSD files the same way as Photoshop and Photopea do, they should work fine in Photopea :)
Published version 28.3.0 with bunch of fixes for section sizes/paddings and missing fields, now almost all of the files correctly open in Photopea.
@photopea One thing I still didn't manage to fix is this file: https://github.com/Agamnentzar/ag-psd/blob/master/test/write/circle/expected.psd There's no effects here, but one simple shape, and Photopea doesn't log any errors in console for this one. If possible can you tell me what is the issue with this one?
In your array of Path Data, Photopea expects the second element to be a type 8: Initial fill rule record. Before the type 0: "Closed Subpath Length Record".
https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577409_17587
Published version 28.3.1 with fixes for vector paths