An external application written in c++ requires me to pass in an image object it would understand i.e. with tostring() method, passing in a encoder and parameters.
How can I get the image and convert it to a string (without saving the image to file)?
image_url is the url to an actual image online i.e http://www.test.com/image1.jpg
This is what I have tried:
def pass_image(image_url):
import base64
str = base64.b64encode(image_url.read())
app = subprocess.Popen("externalApp",
in=subprocess.PIPE,
out=subprocess.PIPE)
app.in.write(str)
app.in.close()
I have also tried to open the image to convert it
image = Image.open(image_url)
but get the error
file() argument 1 must be encoded string without NULL bytes, not str
I think you can get a online image by using requests.get.
You code will be like this:
def pass_image(image_url):
import base64
import requests
str = base64.b64encode(requests.get(image_url).content)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With