27 lines
710 B
Python
27 lines
710 B
Python
from PIL import Image
|
|
from printer_info import *
|
|
|
|
def format_image_to_label(path):
|
|
image = Image.open(path)
|
|
image = image.rotate(-90, expand=True)
|
|
|
|
new_image = Image.new('1', (printer_width, image.height), 1)
|
|
new_image.paste(image, (0, 0))
|
|
|
|
return new_image
|
|
|
|
def format_image(path):
|
|
image = Image.open(path)
|
|
|
|
if (image.height != label_width):
|
|
print("resizing image")
|
|
new_height = label_width
|
|
new_width = int(label_width * image.width / image.height)
|
|
|
|
image = image.resize((new_width, new_height))
|
|
|
|
image = image.convert('1', dither=Image.FLOYDSTEINBERG)
|
|
return image
|
|
|
|
|
|
format_image("static/uploads/upload.png").save("output.png")
|