catdad-experiments / heic-convert

🤳 convert heic/heif images to jpeg and png
252 stars 26 forks source link

Example of usage with a base64 string. #24

Closed jhanson closed 2 years ago

jhanson commented 2 years ago

@catdad Thank you so much for this contribution! I was unfortunately struggling to get this working with our framework ParsePlatform https://parseplatform.org/

We get our files as based64 encoded strings. After converting them to a binary buffer I get this error

Could not parse HEIF file { code: ctor {}, subcode: ctor {} }
[]
ERROR:  Error: HEIF image not found
    at decodeBuffer (/Users/josephhanson/projects/app/node_modules/heic-decode/index.js:57:11)

The code snippet I am using to reproduce this is

 const mediaData = await media.source.getData(); // returns a base64 encoded string of the HEIC image
 const inputBuffer = Buffer.from(mediaData, 'base64');
 const outputBuffer = await convert({
     buffer: Buffer.from(inputBuffer.toString('binary')),
     format: 'JPEG',
     quality: 1,
 });

Do you happen to have an example of using this library with a base64 encoded image?

catdad commented 2 years ago

I'm traveling right now and I don't have a computer to test with. However, I am pretty sure that your inputBuffer should already be a valid buffer. Don't manipulate it further, just pass that in.

jhanson commented 2 years ago

@catdad That was it, thank you for your help. I'll close out this issue