2024-09-25 19:48:36 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2024-09-14 18:49:57 +00:00
|
|
|
from PIL import Image
|
2024-09-15 12:57:26 +00:00
|
|
|
from printer_info import *
|
2024-09-14 18:49:57 +00:00
|
|
|
|
2024-09-15 12:57:26 +00:00
|
|
|
def format_image_to_label(path):
|
2024-09-14 18:49:57 +00:00
|
|
|
image = Image.open(path)
|
|
|
|
image = image.rotate(-90, expand=True)
|
|
|
|
|
2024-09-15 12:57:26 +00:00
|
|
|
new_image = Image.new('1', (printer_width, image.height), 1)
|
2024-09-14 18:49:57 +00:00
|
|
|
new_image.paste(image, (0, 0))
|
|
|
|
|
|
|
|
return new_image
|
|
|
|
|
2024-09-15 12:57:26 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2024-09-17 18:12:24 +00:00
|
|
|
#format_image("static/uploads/upload.png").save("output.png")
|