image - base64 URI to PNG-Python -
i trying generate pdf via python using "reportlab" , add image it. image have use png has format:
data:image/png;base64,ivborw0kggoaaaansuheugaaa+gaaah0cayaaacukactaaagaef (and continues)
i don't know do, first think need transform uri image don't know how , then, use like:
import image im = image.open("infile.png") im.save("outfile.jpg")
in order convert .png .jpg. can me?
try (edit: njzk2 pointing out cut header):
import image, io, base64 data = "data:image/png;base64,ivborw0kggoaaaansuheugaaaauaaaafcayaaacnbyblaaaaheleqvqi12p4//8/w38giaxdibke0dhxgljnbaao9txl0y4ohwaaaabjru5erkjggg==" im = image.open(io.bytesio(base64.b64decode(data.split(',')[1]))) im.save("image.jpg")
added real base64 string testing here, should result in image of little red dot:
Comments
Post a Comment