From 1d43b76bc4adf271aa6c3ba721d56fb14dba4909 Mon Sep 17 00:00:00 2001 From: CodeByMrFinchum Date: Wed, 8 Jan 2025 15:38:03 +0100 Subject: [PATCH] Added function to convert image compatible with qlabel. --- CHANGELOG.md | 4 ++++ src/optima35/core.py | 38 +++++++++++++++++++---------------- src/optima35/image_handler.py | 6 +++++- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 360b30c..8dde563 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog ## 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 - 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. diff --git a/src/optima35/core.py b/src/optima35/core.py index e7e122e..e69cfae 100644 --- a/src/optima35/core.py +++ b/src/optima35/core.py @@ -22,13 +22,13 @@ class OptimaManager: data_for_exif["date_time_original"] = new_time.strftime("%Y:%m:%d %H:%M:%S") 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_output_file, - file_type, - quality, - compressing, - optimize, + file_type = "jpg", + quality = 90, + compressing = 6, + optimize = False, resize = None, watermark = None, font_size = 2, @@ -37,7 +37,8 @@ class OptimaManager: contrast = None, dict_for_exif = None, gps = None, - copy_exif = False): + copy_exif = False, + save = True): # Partly optimized by ChatGPT # Open the image file with self.image_processor.open_image(image_input_file) as img: @@ -47,7 +48,7 @@ class OptimaManager: # Resize if resize is not None: processed_img = self.image_processor.resize_image( - image=processed_img, percent=resize + image=processed_img, percent = resize ) # Watermark @@ -97,13 +98,16 @@ class OptimaManager: except Exception: print("Copying EXIF data selected, but no EXIF data is available in the original image file.") - # Save the processed image - self.image_processor.save_image( - image = processed_img, - path = image_output_file, - piexif_exif_data = exif_piexif_format, - file_type = file_type, - jpg_quality = quality, - png_compressing = compressing, - optimize = optimize - ) + if save: + # Save the processed image + self.image_processor.save_image( + image = processed_img, + path = image_output_file, + piexif_exif_data = exif_piexif_format, + file_type = file_type, + jpg_quality = quality, + png_compressing = compressing, + optimize = optimize + ) + else: + return self.image_processor.convert_pil_to_qtimage(processed_img) diff --git a/src/optima35/image_handler.py b/src/optima35/image_handler.py index 33f47a0..c42a66e 100644 --- a/src/optima35/image_handler.py +++ b/src/optima35/image_handler.py @@ -1,4 +1,4 @@ -from PIL import Image, ImageDraw, ImageFont, ImageEnhance +from PIL import Image, ImageDraw, ImageFont, ImageEnhance, ImageQt import piexif from fractions import Fraction @@ -91,6 +91,10 @@ class ImageProcessor: except Exception as 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: """Function using piexif are here.""" def __init__(self):