0

I have a image in the server folder. In my do_GET() function which handles the Get request I would like to send a image back. I choose to use the self.wfile.write(''). Can anyone tell me how to include the source of the image in to the img tag? Or is there a better way to do this? Thanks.

1
  • 2
    Are you writing a webserver? If not, then use a webserver for serving static assets to your application. Commented Mar 18, 2013 at 4:26

1 Answer 1

1

You can include the "source" of an image in the img tag using a data URI like this:

<img alt="Embedded Image" src="data:image/png;base64,<your base64 encoding here>" />

Generate the base64 string using the base64 python standard lib:

import base64

with open("image.png", "rb") as image:
    encoded_string = base64.b64encode(image.read())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.