Spaces:
Sleeping
Sleeping
File size: 769 Bytes
4f7b4af |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import io
import tempfile
from PIL import Image
def create_temp_file(text_file):
# create a local tempfile of file that was selected to be uploaded
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as tmp:
tmp.write(text_file.getvalue())
tmp_path = tmp.name # Save the path where the tempfile has been written
return tmp_path
def get_image_bytes(image_file):
# Open the image file
image_path = image_file # Replace with the path to your image file
image = Image.open(image_path)
# Convert the image to bytes
with io.BytesIO() as output:
image.save(output, format="png") # Change the format as needed (e.g., JPEG, PNG)
image_bytes = output.getvalue()
return image_bytes |