()
| 196 | |
| 197 | |
| 198 | def save_image(): |
| 199 | global text_label, loaded_image, file_path, user_text, img, new_x, new_y, logo |
| 200 | if loaded_image and text_label: |
| 201 | width, height = img.size |
| 202 | canvas_width = image_canvas.winfo_width() |
| 203 | canvas_height = image_canvas.winfo_height() |
| 204 | |
| 205 | scale_x = width / canvas_width |
| 206 | scale_y = height / canvas_height |
| 207 | |
| 208 | image_x = int(new_x * scale_x) - 10 |
| 209 | image_y = int(new_y * scale_y) - 10 |
| 210 | |
| 211 | adjusted_font_size = int(int(font_size.get()) * min(scale_x, scale_y)) + 6 |
| 212 | watermarked_image = watermark.add_text_watermark( |
| 213 | image=img, |
| 214 | text=user_text, |
| 215 | position=(image_x, image_y), |
| 216 | text_color=color_code, |
| 217 | font_style=f"fonts/{font_style.get()}.ttf", |
| 218 | font_size=adjusted_font_size, |
| 219 | ) |
| 220 | |
| 221 | watermark.save_image(watermarked_image) |
| 222 | |
| 223 | elif loaded_image and logo_path is not None: |
| 224 | original_image = img.convert("RGBA") |
| 225 | canvas_width = image_canvas.winfo_width() |
| 226 | canvas_height = image_canvas.winfo_height() |
| 227 | |
| 228 | logo_image = Image.open(logo_path) |
| 229 | logo_resized = logo_image.resize( |
| 230 | ( |
| 231 | int(original_image.width * 0.2) + 50, |
| 232 | int(original_image.height * 0.2), |
| 233 | ) |
| 234 | ) |
| 235 | |
| 236 | image_width, image_height = original_image.size |
| 237 | logo_position = ( |
| 238 | int(new_x * image_width / canvas_width), |
| 239 | int(new_y * image_height / canvas_height), |
| 240 | ) |
| 241 | |
| 242 | watermark.add_logo( |
| 243 | image=original_image, logo=logo_resized, position=logo_position |
| 244 | ) |
| 245 | |
| 246 | watermark.save_image(original_image) |
| 247 | |
| 248 | |
| 249 | # -------------------Tab View AND OPEN IMAGE----------- |
nothing calls this directly
no test coverage detected