Added function to convert image compatible with qlabel.

This commit is contained in:
Mr Finchum 2025-01-08 15:38:03 +01:00
parent 8e56565b29
commit 1d43b76bc4
3 changed files with 30 additions and 18 deletions

View file

@ -1,6 +1,10 @@
# Changelog # Changelog
## 0.6.x ## 0.6.x
### 0.6.5-a
- No breaking changes to backward compatibility yet.
- Updated the `process` function: an image can now be returned in a modified form without saving. It is returned as a Qt image, which is required for the new UI functionality.
### 0.6.4 ### 0.6.4
- Released a stable-ish version to ensure compatibility with the current GUI in OptimaLab35 (v0.1.0). - Released a stable-ish version to ensure compatibility with the current GUI in OptimaLab35 (v0.1.0).
- This version serves as a baseline before potential breaking changes in future updates. - This version serves as a baseline before potential breaking changes in future updates.

View file

@ -22,13 +22,13 @@ class OptimaManager:
data_for_exif["date_time_original"] = new_time.strftime("%Y:%m:%d %H:%M:%S") data_for_exif["date_time_original"] = new_time.strftime("%Y:%m:%d %H:%M:%S")
return data_for_exif return data_for_exif
def process_image(self, def process_image(self, #split into two classes, one for modification for one saving..
image_input_file, image_input_file,
image_output_file, image_output_file,
file_type, file_type = "jpg",
quality, quality = 90,
compressing, compressing = 6,
optimize, optimize = False,
resize = None, resize = None,
watermark = None, watermark = None,
font_size = 2, font_size = 2,
@ -37,7 +37,8 @@ class OptimaManager:
contrast = None, contrast = None,
dict_for_exif = None, dict_for_exif = None,
gps = None, gps = None,
copy_exif = False): copy_exif = False,
save = True):
# Partly optimized by ChatGPT # Partly optimized by ChatGPT
# Open the image file # Open the image file
with self.image_processor.open_image(image_input_file) as img: with self.image_processor.open_image(image_input_file) as img:
@ -47,7 +48,7 @@ class OptimaManager:
# Resize # Resize
if resize is not None: if resize is not None:
processed_img = self.image_processor.resize_image( processed_img = self.image_processor.resize_image(
image=processed_img, percent=resize image=processed_img, percent = resize
) )
# Watermark # Watermark
@ -97,13 +98,16 @@ class OptimaManager:
except Exception: except Exception:
print("Copying EXIF data selected, but no EXIF data is available in the original image file.") print("Copying EXIF data selected, but no EXIF data is available in the original image file.")
# Save the processed image if save:
self.image_processor.save_image( # Save the processed image
image = processed_img, self.image_processor.save_image(
path = image_output_file, image = processed_img,
piexif_exif_data = exif_piexif_format, path = image_output_file,
file_type = file_type, piexif_exif_data = exif_piexif_format,
jpg_quality = quality, file_type = file_type,
png_compressing = compressing, jpg_quality = quality,
optimize = optimize png_compressing = compressing,
) optimize = optimize
)
else:
return self.image_processor.convert_pil_to_qtimage(processed_img)

View file

@ -1,4 +1,4 @@
from PIL import Image, ImageDraw, ImageFont, ImageEnhance from PIL import Image, ImageDraw, ImageFont, ImageEnhance, ImageQt
import piexif import piexif
from fractions import Fraction from fractions import Fraction
@ -91,6 +91,10 @@ class ImageProcessor:
except Exception as e: except Exception as e:
print(f"Failed to save image: {e}") print(f"Failed to save image: {e}")
def convert_pil_to_qtimage(self, pillow_image):
qt_image = ImageQt.ImageQt(pillow_image)
return qt_image
class ExifHandler: class ExifHandler:
"""Function using piexif are here.""" """Function using piexif are here."""
def __init__(self): def __init__(self):