Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(17): add IGN in exif as processingSoftware #33

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions ImageGoNord/GoNord.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import threading

from PIL import Image, ImageFilter
from PIL import Image, ImageFilter, ExifTags

import numpy as np
import ffmpeg
Expand Down Expand Up @@ -167,6 +167,9 @@ class GoNord(object):
TRANSPARENCY_TOLERANCE = 190
MAX_THREADS = 10

EXIF_IGN = "ImageGoNord by Schroedinger Hat"
EXIF_IGN_AI = "ImageGoNord AI by Schroedinger Hat"

PALETTE_NET_REPO_FOLDER = 'https://github.com/Schrodinger-Hat/ImageGoNord-pip/raw/master/ImageGoNord/models/PaletteNet/'

AVAILABLE_PALETTE = []
Expand Down Expand Up @@ -254,6 +257,9 @@ def open_image(self, path):
opened_image = Image.open(path)
if (type(opened_image.getpixel((0,0))) == int):
opened_image = opened_image.convert('RGB')

exif = opened_image.getexif()
exif[ExifTags.Base.ProcessingSoftware] = self.EXIF_IGN

return opened_image

Expand Down Expand Up @@ -301,7 +307,8 @@ def image_to_base64(self, image, extension):
processed image
"""
im_file = BytesIO()
image.save(im_file, format=extension)
exif = image.getexif()
image.save(im_file, format=extension, exif=exif)
im_bytes = im_file.getvalue()
return base64.b64encode(im_bytes)

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

if (save_path != ''):
self.save_image_to_file(quantize_img, save_path)
Expand Down Expand Up @@ -544,10 +553,14 @@ def convert_image(self, image, save_path='', use_model=False, use_model_cpu=Fals
original_image.close()
pixels = self.load_pixel_image(image)
is_rgba = (image.mode == 'RGBA')
exif = image.getexif()
exif[ExifTags.Base.ProcessingSoftware] = self.EXIF_IGN

if use_model:
if torch != None:
image = self.convert_image_by_model(image, use_model_cpu)
exif = image.getexif()
exif[ExifTags.Base.ProcessingSoftware] = self.EXIF_IGN_AI
else:
print('Please install the dependencies required for the AI feature: pip install image-go-nord[AI]')
else:
Expand Down Expand Up @@ -585,7 +598,8 @@ def save_image_to_file(self, image, path):
path : str
the path and the filename where to save the image
"""
image.save(path)
exif = image.getexif()
image.save(path, exif=exif)



Expand Down