I was able to extract b64 encoded image data by printing the response.content when using โacceptโ: โapplication/jsonโ, in the header.
I feel confident that there are much easier ways of achieving what I have, but this is what I got to work for now.
I have limited experience with python, JSON, and http requests so I had to work for it to get the images.
I used a online service that will convert b64 encoded data to jpg
https://onlinejpgtools.com/convert-base64-to-jpg
The response.content has some JSON characters in there and is two images as is mentioned in the tutorial.
For me the start of an image always started with /9j/ and ended with = signs so I cleaned up the data and got the converted jpg.
My first test was with an image of lower resolution I think, so I tried again with a higher resolution on the second pass. I also took the output toonified image and processed it again to see what happeded.
Here are the results:
I used the newest form of Python(3.9)
and made sure to have Python requests library by using python -m pip install requests
And here is the python code.
import requests
url = "https://toonify.p.rapidapi.com/v0/toonify"
files = {"image": open("toonifyOutput2.jpg", "rb")}
querystring = {"proceed_without_face":"false","face_index":"0","crop_edges":"0","return_aligned":"true"}
headers = {
"accept": "application/json",
'x-rapidapi-host': "toonify.p.rapidapi.com",
'x-rapidapi-key': ~~~~apiKey~~~~"
}
response = requests.request("POST", url, files=files, headers=headers, params=querystring)
results = response.content
print (results)
print("Operation Complete")
Join in the discussion - add comment below: