Skip to content

Commit 31aab4c

Browse files
committed
2 parents 2066dfe + 1ecc09b commit 31aab4c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

ImageGoNord/GoNord.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import threading
88

9-
from PIL import Image, ImageFilter
9+
from PIL import Image, ImageFilter, ExifTags
1010

1111
import numpy as np
1212
import ffmpeg
@@ -167,6 +167,9 @@ class GoNord(object):
167167
TRANSPARENCY_TOLERANCE = 190
168168
MAX_THREADS = 10
169169

170+
EXIF_IGN = "ImageGoNord by Schroedinger Hat"
171+
EXIF_IGN_AI = "ImageGoNord AI by Schroedinger Hat"
172+
170173
PALETTE_NET_REPO_FOLDER = 'https://github.com/Schrodinger-Hat/ImageGoNord-pip/raw/master/ImageGoNord/models/PaletteNet/'
171174

172175
AVAILABLE_PALETTE = []
@@ -254,6 +257,9 @@ def open_image(self, path):
254257
opened_image = Image.open(path)
255258
if (type(opened_image.getpixel((0,0))) == int):
256259
opened_image = opened_image.convert('RGB')
260+
261+
exif = opened_image.getexif()
262+
exif[ExifTags.Base.ProcessingSoftware] = self.EXIF_IGN
257263

258264
return opened_image
259265

@@ -301,7 +307,8 @@ def image_to_base64(self, image, extension):
301307
processed image
302308
"""
303309
im_file = BytesIO()
304-
image.save(im_file, format=extension)
310+
exif = image.getexif()
311+
image.save(im_file, format=extension, exif=exif)
305312
im_bytes = im_file.getvalue()
306313
return base64.b64encode(im_bytes)
307314

@@ -394,6 +401,8 @@ def quantize_image(self, image, fill_color='2E3440', save_path=''):
394401
palimage = Image.new('P', (1, 1))
395402
palimage.putpalette(data_colors)
396403
quantize_img = quantize_to_palette(image, palimage)
404+
exif = quantize_img.getexif()
405+
exif[ExifTags.Base.ProcessingSoftware] = self.EXIF_IGN
397406

398407
if (save_path != ''):
399408
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
544553
original_image.close()
545554
pixels = self.load_pixel_image(image)
546555
is_rgba = (image.mode == 'RGBA')
556+
exif = image.getexif()
557+
exif[ExifTags.Base.ProcessingSoftware] = self.EXIF_IGN
547558

548559
if use_model:
549560
if torch != None:
550561
image = self.convert_image_by_model(image, use_model_cpu)
562+
exif = image.getexif()
563+
exif[ExifTags.Base.ProcessingSoftware] = self.EXIF_IGN_AI
551564
else:
552565
print('Please install the dependencies required for the AI feature: pip install image-go-nord[AI]')
553566
else:
@@ -585,7 +598,8 @@ def save_image_to_file(self, image, path):
585598
path : str
586599
the path and the filename where to save the image
587600
"""
588-
image.save(path)
601+
exif = image.getexif()
602+
image.save(path, exif=exif)
589603

590604

591605

0 commit comments

Comments
 (0)