react-imgpro icon indicating copy to clipboard operation
react-imgpro copied to clipboard

Can't use Base64 as source

Open trainbolt opened this issue 7 years ago • 11 comments

It would be really handy to be able to use base64 as the image instead of a URL... do you know of a way to do this?

This looks amazing and I'd really love to be able to use it.

Thanks.

trainbolt avatar Jan 10 '18 20:01 trainbolt

I kinda got it to work. jimp (the underlying image-processing libarary) can handle different inputs. With the function from this gist you can transform the base64 url into a Uint8Array and grab the buffer from there.

const base64File = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA...'
const readableFile = convertDataURIToBinary(base64Image).buffer;

<ProcessImage image={readableFile}/>

Unfortunately another script (browser-image-resize) is throwing an error but the image filters i used are applied correctly. Don't know if resizing will still work though.

Still, it would be nice to see this handled in a better way, since it's a quite common usecase. Image Upload -> Base64 -> do some transformation ... -> Send to server.

mimimimichael avatar Feb 19 '18 15:02 mimimimichael

Yup! This totally makes sense. I will look into this issue this week. Sorry, I've been busy lately with some other projects and didn't notice @trainbolt suggestion.

nitin42 avatar Feb 20 '18 18:02 nitin42

Can you tell me exactly what sort of error occurs due to browser-image-resize ?

nitin42 avatar Feb 20 '18 18:02 nitin42

Also, it would be nice if you could share an example of how you are using the base64 images with jimp.

nitin42 avatar Feb 20 '18 18:02 nitin42

@alotov-agina I'd be open to a PR for this. I am busy with some other work. But I can help you with this work,

Thanks!

nitin42 avatar Mar 03 '18 17:03 nitin42

is there any solution available for this?

mrjosshi avatar Mar 28 '18 11:03 mrjosshi

You can use probe-image-size instead of browser-image-size to support base64.

nitin42 avatar Mar 28 '18 11:03 nitin42

is it another dependency where i need to add this? could you please clear this in details or any example for this TIA

mrjosshi avatar Mar 29 '18 05:03 mrjosshi

Sorry, I've been busy lately. So, the error is being caused by the dependency "browser-image-size". To make it work (base64), you need to replace that dependency with "prob-image-size". That's it!

nitin42 avatar Mar 29 '18 20:03 nitin42

Sorry, I've been busy lately. So, the error is being caused by the dependency "browser-image-size". To make it work (base64), you need to replace that dependency with "prob-image-size". That's it!

Hi, I tried this solution, but then probe-image-size is throwing a weird error: "TypeError: merge is not a function" when I do have deepmerge installed. Is there a solution for that? Thanks!

yueHan98 avatar Sep 17 '18 12:09 yueHan98

It seems that I've fixed the TypeError which is caused by the deepmerge package the probe-image-size package is relying on. However, now the componentDidMount function in main.js is throwing a "options.uri is a required argument" error and I'm wondering if you could give me a hint on how to fix that. Thanks in advance. :)

yueHan98 avatar Sep 17 '18 13:09 yueHan98