I was thinking about creating an image of appropriate input information with PIL, expanding the file into a temporary directory, and displaying it in the browser.
I created a temporary directory with NamedTemporaryFile, created a file there, and specified it with an HTML img tag.
Is there any way to save the image created on the server side in memory and display it in the browser even if it is not a temporary directory?
python is supposed to use django with 3.7, and it is specified as MEDIA_URL =/media /.
font_color = (0, 0, 0) im = Image.new ('RGBA', (60,60), (0, 0, 0, 0)) draw = ImageDraw.Draw (im) draw.text ((0,0), req.POST ["req_string"], font_color) #Physical directory path = "/file/hoge/media/test.png" img.save (path) # Tried a temporary directory on the way with tempfile.NamedTemporaryFile (delete = False) as tf: temp_file_name = tf.name path = "/ file/hoge/media /" + temp_file_name + "test.png"
Answer # 1
Is there any way to save the image created on the server side in memory and display it in the browser?
It is possible to encode the data URI and export it on HTML.
Answer # 2
fp – A filename (string), pathlib.Path object or file object.
, you can specify a file object instead of a file name as the first argument.
The io module also has a file object "
BytesIO" that can be read from and written to memory.
With this combined technique, PIL can be saved in memory.
# coding: utf-8 import sys, io from PIL import Image if __name__ == '__main__': img = Image.new ('RGB', (64, 64), (0, 255, 0)) f = io.BytesIO () img.save (f, 'png') # Try exporting to a file for confirmation. with open ('hoge.png', 'wb') as out_f: out_f.write (f.getvalue ())
I don't know django, so I don't know the future,
Response that returns a Django image
Make a response that returns an image like the one above, and specify the URL in the src attribute of the img tag.
- i want to display an image using opencv from python
- python - display the image file saved by django
- python - confusion matrix display in image recognition on cnn
- image display in python
- python - how to display an image, make a selection, and process by selection
- python image display error beginner, thank you
- how to scrape in python and display in a browser?
- python 3x - display on another screen, insert value
- css - i want to reverse the image and text display on mobile with wordpress lightning media and text
- python - about the problem that the screen display does not work when i have multiple apps in django
- python 3x - i want to display the message acquired by websockets with for
- python - display another widget when the button is pressed
- python - i want to find the average hsv value for each divided image
- c ++ - i want to put a bgr image in the memory area of a dynamic object
- python - i want to display db other than'default'of django with genericdetailview
- image recognition using python beginner pyautogui is not possible
- python - pygame image drawing doesn't work
- html - i want to save the svg image on the site and display it on chrome
- python - i want to compare images and find the same image
- python 3x - python i want to display only files with the specified extension
- python - i want to display the my page button only to users who have logged in with django, but there is a problem
- python - how to enable selection by value when selecting a selection format column
- python - psycopg2 cannot be read by pycharm
- python - if you create multiple signup screens with django, you want to change the redirect destination in case of an error
- [python 390] seven-series if statement does not work
- python - django form i want to write a little smarter
- python - i don't know what's wrong with an error in serialize on the django rest framework
- python - wait for user reaction using wait_for method in discordpy