From 36d2c329759d88d9c15773ce956b6d60122efc3f Mon Sep 17 00:00:00 2001 From: Mr Finchum Date: Sat, 28 Dec 2024 10:51:18 +0000 Subject: [PATCH] Merge image_handler from TUI fork --- CHANGELOG.md | 3 +++ README.md | 21 +++++++++------------ config/exif_options.yaml | 1 + main.py | 6 ++++-- utils/image_handler.py | 11 +++++++++-- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcb2a80..a6bf924 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## 0.2.x +### 0.2.1: Merge from TUI fork +- Ensure watermark is white with black borders. + ### 0.2.0 - **Cleaner folder structure** - Moving files with classes to different folder to keep project cleaner. diff --git a/README.md b/README.md index 015a48d..1b44be7 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ This project is a *port* of my earlier work, an collection of [bash script](https://gitlab.com/sf-bashscripts/analogphotography), transitioning functionality to a more modular and maintainable design. -The primary focus is on building a terminal-based user interface (TUI). Initially, the interface will utilize `simple_term_menu`, with plans to expand to `textual` for a more dynamic TUI experience in the future. - **Please check** if a new branch is available and read the **changelog** to see the progress and current features of the program. The README might sometimes lag behind. ## **Current Status** @@ -15,25 +13,24 @@ The primary focus is on building a terminal-based user interface (TUI). Initiall - Additionally, while EXIF data/metadata should be implemented correctly, there is a possibility of overlooked issues. In the worst case, a program might throw an error when handling EXIF data, though this has not occurred so far. ### Available Features: -- Initial basic TUI functionality using `simple_term_menu` (planned to switch to a different interface later). -- Core features, including image resizing, metadata management, and YAML configuration. - -## Key Features - -- Intuitive TUI for organizing and editing metadata and image properties. -- Improved modularity with classes split into separate files for flexibility and maintainability. -- Supports essential tasks like reading, editing, and saving EXIF data, as well as resizing and processing images. +- Initial basic TUI functionality using `simple_term_menu` +- Core features: + - resizing + - renaming + - grayscale + - Change brightness + - Change contrast + - Exif management + - Add watermark **Gif of program in action** - ![my-gif](https://gitlab.com/python_projects3802849/optima-35/-/raw/main/media/v0.1.0-demo.gif?ref_type=heads) ## Dependencies To run **OPTIMA-35**, the following Python libraries are required: -- **textual**: For building TUI (planned future updates). - **pyyaml**: To handle YAML files for configuration and settings. - **piexif**: To read, modify, and write EXIF metadata. - **Pillow**: For image processing. diff --git a/config/exif_options.yaml b/config/exif_options.yaml index 9a80688..8fd1521 100644 --- a/config/exif_options.yaml +++ b/config/exif_options.yaml @@ -1,3 +1,4 @@ +# Example file. You can add and remove entries here. make: - Nikon model: diff --git a/main.py b/main.py index 058dd2b..575a5ea 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,8 @@ from ui.tui import SimpleTUI class Optima35: # The layout of class Optima35 was originally made by ChatGPT, but major adjustments have been made. To remain transparent, I disclose this. def __init__(self, settings_file, exif_options_file): - self.version = "0.2.0" + self.name = "OPTIMA-35" + self.version = "0.2.1" self.utilities = Utilities() self.image_processor = ImageProcessor() self.exif_handler = ExifHandler() @@ -132,7 +133,8 @@ class Optima35: self.settings["output_folder"] = input("Enter path of output folder: ").strip() self.settings["file_format"] = self.take_input_and_validate(question = "Enter export file format (jpg, png, webp): ", accepted_input = ["jpg", "png", "webp"], accepted_type = str) self.settings["modifications"] = self.tui.multi_select_menu( - "Select what you want to do", menu_options + f"\n{self.name} v.{self.version} \nSelect what you want to do (esc or q to exit)", + menu_options ) if "Change EXIF" not in self.settings["modifications"]: self.settings["copy_exif"] = self.tui.yes_no_menu("Do you want to copy exif info from original file?") diff --git a/utils/image_handler.py b/utils/image_handler.py index 6631a93..77a94b7 100644 --- a/utils/image_handler.py +++ b/utils/image_handler.py @@ -47,13 +47,20 @@ class ImageProcessor: font = ImageFont.truetype("OpenDyslexic3-Regular.ttf", font_size) except: print("Error loading font for watermark, please ensure font is installed...\n") - time.sleep(0.3) + time.sleep(0.1) return image c, w, textwidth, textheight, = drawer.textbbox(xy = (0, 0), text = text, font = font) # Getting text size, only need the last two values x = imagewidth - textwidth - margin y = imageheight - textheight - margin - drawer.text((x, y), text, font = font) + + # thin border + drawer.text((x-1, y), text, font=font, fill=(64, 64, 64)) + drawer.text((x+1, y), text, font=font, fill=(64, 64, 64)) + drawer.text((x, y-1), text, font=font, fill=(64, 64, 64)) + drawer.text((x, y+1), text, font=font, fill=(64, 64, 64)) + # Adding text in the desired color + drawer.text((x, y), text, font = font, fill=(255, 255, 255)) return image