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

How to pass Buffer as argument instead of path? How to solve following error? #18

Closed
mounikakella opened this issue Oct 14, 2019 · 3 comments

Comments

@mounikakella
Copy link

mounikakella commented Oct 14, 2019

Basically, I have image info in base64 encoded. so, I'm converting the base64 to buffer by using the following code

const thumbnailBuffer = await Buffer.from(thumbnailBase64, "base64");
The Buffer im passing looks like this to the rotate() function.
buffer <Buffer 75 ab 5a 8a 66 a0 7b fa 67 81 b6 ac 7b ae 22 54 13 91 c3 42 86 82 80 00 00 03 52 52 11 14 80 00 00 3b c0 00 00 3b c2 00 80 00 00 25 44 85 3b 80 00 00 ... 8626 more bytes>
Below is the error when Im executing.

An error occurred when rotating the file: Could not read EXIF data (Error: 'load' gots invalid file data.)
(node:21457) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'width' of undefined
    at PDFDocument.image (/home/user/***/***/***/node_modules/pdfkit/js/mixins/images.js:27:17)
    at WriteStream.<anonymous> (/home/user/***/***/***/***/***/file.js:192:11)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
(node:21457) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:21457) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Done in 2.17s.

Please LMK if Im doing any wrong.

@stonetwig
Copy link

stonetwig commented Oct 22, 2019

If you have your image encoded as base64 you can do the following to get a file buffer:

const fileBuffer = new Buffer(file.replace(/^data:.+;base64,/, ""), 'base64');

Then you can use the rotate method:
const rotateResult = await jo.rotate(fileBuffer, {quality: 100});

I hope that helps your case!

@mounikakella
Copy link
Author

mounikakella commented Oct 30, 2019 via email

@johansatge
Copy link
Owner

Hello,

since this error was impossible to reproduce, I will go ahead and close the issue.

Please do not hesitate to reopen if you still reproduce and have a more complete example to share :)

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

3 participants