0

So I have an image cropper and its allowing the user to set the size of the image. The image returned after it is cropped is in this form:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtwAAALcCAYAAADUqWdpAAAgAElEQVR4Xux9...

However, when I try to decode this, i'm told that it is not in the correct format... What is going on here?

EDIT: I'm using var base64 = require('base-64'); base64.decode(string);

EDIT: Full return value: https://pastebin.com/vsHBq3pR

J Dorrian
  • 206
  • 3
  • 15
  • 2
    Plz post your decoding code and the exact error, also would be helpful if you had an example base64 that doesn't work (of say a single filled colour to keep it small) – Dominic Mar 01 '18 at 17:00
  • I've attached the base64 that I cannot decode to the post, not sure what you mean by a filled colour, i'm only trying to decode this image – J Dorrian Mar 01 '18 at 17:07
  • 1
    If you paste the (huge) string into the URL bar of a browser, it does decode and show a correct image of a slight gradient. (An SVG of the same would be far shorter. Just saying.) – 9000 Mar 01 '18 at 17:12
  • @DominicTobias I'm trying several methods but this is my current best attempt: utf8.decode(base64.decode(this.state.postCrop.substr(21)))) – J Dorrian Mar 01 '18 at 17:26

0 Answers0