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 convert to base64 encoded string to Image Object ? #610

Closed
vyas315 opened this issue Mar 21, 2017 · 8 comments
Closed

How to convert to base64 encoded string to Image Object ? #610

vyas315 opened this issue Mar 21, 2017 · 8 comments

Comments

@vyas315
Copy link

vyas315 commented Mar 21, 2017

No description provided.

@timholy
Copy link
Member

timholy commented Mar 21, 2017

It isn't possible to tell from that information alone. Did you try img = base64decode(str)? Another option might be that it's a base64-encoded PNG, in which case using using FileIO; load(Stream(format"PNG", stream)) might work.

@vyas315
Copy link
Author

vyas315 commented Mar 21, 2017

I have the string of the following format
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABQAAAAJnCAYAA....."
I tried img = base64decode(str), which returned a 1-D array,

Is there a way to get Image object from this string (which is base64 encode of a canvas object in javascript) ??

@timholy
Copy link
Member

timholy commented Mar 21, 2017

Since that's image/png;base64, try the Stream version I showed you above.

@timholy
Copy link
Member

timholy commented Mar 21, 2017

Or even better, maybe readblob from ImageMagick. Demo:

julia> str = readstring("lighthouse.png");

julia> using ImageMagick

julia> img = readblob(str.data)

@vyas315
Copy link
Author

vyas315 commented Mar 22, 2017

@timholy Thanks a lot, readblob() worked !!

@timholy
Copy link
Member

timholy commented Mar 22, 2017

Great, glad to hear it.

@Losses
Copy link

Losses commented Aug 20, 2019

@timholy format"PNG" seems not working anymore, what should we use in 2019?

@timholy
Copy link
Member

timholy commented Aug 23, 2019

Should work. Can you provide an example I can copy/paste?

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