|
6 | 6 |
|
7 | 7 | import threading
|
8 | 8 |
|
9 |
| -from PIL import Image, ImageFilter |
| 9 | +from PIL import Image, ImageFilter, ExifTags |
10 | 10 |
|
11 | 11 | import numpy as np
|
12 | 12 | import ffmpeg
|
@@ -167,6 +167,9 @@ class GoNord(object):
|
167 | 167 | TRANSPARENCY_TOLERANCE = 190
|
168 | 168 | MAX_THREADS = 10
|
169 | 169 |
|
| 170 | + EXIF_IGN = "ImageGoNord by Schroedinger Hat" |
| 171 | + EXIF_IGN_AI = "ImageGoNord AI by Schroedinger Hat" |
| 172 | + |
170 | 173 | PALETTE_NET_REPO_FOLDER = 'https://github.com/Schrodinger-Hat/ImageGoNord-pip/raw/master/ImageGoNord/models/PaletteNet/'
|
171 | 174 |
|
172 | 175 | AVAILABLE_PALETTE = []
|
@@ -254,6 +257,9 @@ def open_image(self, path):
|
254 | 257 | opened_image = Image.open(path)
|
255 | 258 | if (type(opened_image.getpixel((0,0))) == int):
|
256 | 259 | opened_image = opened_image.convert('RGB')
|
| 260 | + |
| 261 | + exif = opened_image.getexif() |
| 262 | + exif[ExifTags.Base.ProcessingSoftware] = self.EXIF_IGN |
257 | 263 |
|
258 | 264 | return opened_image
|
259 | 265 |
|
@@ -301,7 +307,8 @@ def image_to_base64(self, image, extension):
|
301 | 307 | processed image
|
302 | 308 | """
|
303 | 309 | im_file = BytesIO()
|
304 |
| - image.save(im_file, format=extension) |
| 310 | + exif = image.getexif() |
| 311 | + image.save(im_file, format=extension, exif=exif) |
305 | 312 | im_bytes = im_file.getvalue()
|
306 | 313 | return base64.b64encode(im_bytes)
|
307 | 314 |
|
@@ -394,6 +401,8 @@ def quantize_image(self, image, fill_color='2E3440', save_path=''):
|
394 | 401 | palimage = Image.new('P', (1, 1))
|
395 | 402 | palimage.putpalette(data_colors)
|
396 | 403 | quantize_img = quantize_to_palette(image, palimage)
|
| 404 | + exif = quantize_img.getexif() |
| 405 | + exif[ExifTags.Base.ProcessingSoftware] = self.EXIF_IGN |
397 | 406 |
|
398 | 407 | if (save_path != ''):
|
399 | 408 | self.save_image_to_file(quantize_img, save_path)
|
@@ -544,10 +553,14 @@ def convert_image(self, image, save_path='', use_model=False, use_model_cpu=Fals
|
544 | 553 | original_image.close()
|
545 | 554 | pixels = self.load_pixel_image(image)
|
546 | 555 | is_rgba = (image.mode == 'RGBA')
|
| 556 | + exif = image.getexif() |
| 557 | + exif[ExifTags.Base.ProcessingSoftware] = self.EXIF_IGN |
547 | 558 |
|
548 | 559 | if use_model:
|
549 | 560 | if torch != None:
|
550 | 561 | image = self.convert_image_by_model(image, use_model_cpu)
|
| 562 | + exif = image.getexif() |
| 563 | + exif[ExifTags.Base.ProcessingSoftware] = self.EXIF_IGN_AI |
551 | 564 | else:
|
552 | 565 | print('Please install the dependencies required for the AI feature: pip install image-go-nord[AI]')
|
553 | 566 | else:
|
@@ -585,7 +598,8 @@ def save_image_to_file(self, image, path):
|
585 | 598 | path : str
|
586 | 599 | the path and the filename where to save the image
|
587 | 600 | """
|
588 |
| - image.save(path) |
| 601 | + exif = image.getexif() |
| 602 | + image.save(path, exif=exif) |
589 | 603 |
|
590 | 604 |
|
591 | 605 |
|
|
0 commit comments