I\'m trying to load image from string like as PHP function imagecreatefromstring
How can I do that?
I have MySQL blob field image. I\'m using
I think this answer provided on this stackoverflow question is a better answer for this question.
Quoting details (borrowed from @lamhoangtung from above linked answer)
import base64
import json
import cv2
import numpy as np
response = json.loads(open('./0.json', 'r').read())
string = response['img']
jpg_original = base64.b64decode(string)
jpg_as_np = np.frombuffer(jpg_original, dtype=np.uint8)
img = cv2.imdecode(jpg_as_np, flags=1)
cv2.imwrite('./0.jpg', img)