Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large files #154

Open
Veragin opened this issue Nov 30, 2018 · 6 comments
Open

Large files #154

Veragin opened this issue Nov 30, 2018 · 6 comments

Comments

@Veragin
Copy link

Veragin commented Nov 30, 2018

Hi,

I started using this awsome library. But it has problems with large file (like 100MB and larger)("has problems" means cannot read several image layers). I know there is a lot of articles, saying that, this library is not suitable for large files. But it is possible. Look at https://www.photopea.com/. Its free online photoshop and it can read large .psd files.

I made some research. The problem is with using method toPng():
var des = psd.tree().descendants()[0]; var img = (des.get('image')).toPng();
It returns an image of the layer. It works fine, but allocates a lot of memory, which is not released (for example for 100MB psd file, allocates 300MB for one image (layer)). Its because after using toPng() method, the object psd stores information about layer, like pixelData and so on.

This is 100% fine. But why the pixelData stores information (which are only integers between 0-255) as an classic array. I suggest use Uint8ClampedArray array. I believe that this improvement will reduce the memory size of the pixelData array more than 10 times.

This Uint8ClampedArray array is used also in ImageData object (acquired from canvas HTML element). Here is a figure:
image

I hope my text is comprehensible to developers at least.

@rtf-const
Copy link

there is already merged PR for this issue, but isn't released yet #135
so you can work with large files by using master branch instead of version published in npm

@Veragin
Copy link
Author

Veragin commented Dec 5, 2018

I have already seen your issue (#139) and your solve. I forgot to mention that i am using this library in browser (the psd.js file (or psd.min.js file)). And these files are not corrected. Or I didnt find the right ones.

@rtf-const
Copy link

You can build psd.js and psd.min.js usong following commands:

npm install --production
cake compile

or, under Windows

node .\node_modules\coffee-script\bin\cake compile

I attached compilled files that use typed arrays. I hope it helps

dist.zip

@Veragin
Copy link
Author

Veragin commented Dec 11, 2018

Thank you very much. You are a genius.

@SteinNs
Copy link

SteinNs commented Dec 18, 2018

there is already merged PR for this issue, but isn't released yet #135
so you can work with large files by using master branch instead of version published in npm

What time will this version be released?

@thang551999
Copy link

thang551999 commented Apr 7, 2022

I also using a large PSD file on browser ( size about 1.2 GB or bigger). And I receive a error:

ERROR: Uncaught (in promise) RangeError: Array buffer allocation failed

Can anyone help me to solve this, pls ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants