Skip to content

Commit

Permalink
Use fault-tolerant PNG loading (Fix issue #14).
Browse files Browse the repository at this point in the history
  • Loading branch information
Poikilos committed Apr 11, 2024
1 parent cbb2184 commit cc46d19
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions channeltinkerpil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
)

ImageFile.LOAD_TRUNCATED_IMAGES = True
# ^ Avoids issue #14 (GIMP images with
# "Raw profile type exif"), and image is displayed
# (often image isn't really broken,
# such as if saved with GIMP)


def gen_diff_image(base, head, diff=None, diff_path=None):
Expand Down
9 changes: 8 additions & 1 deletion channeltinkerpil/diffimagetk.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import OrderedDict
import tkinter as tk
import PIL
from PIL import ImageTk, Image
from PIL import ImageTk, ImageFile, Image

if __name__ == "__main__":
MODULE_DIR = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -16,6 +16,13 @@
gen_diff_image,
)

ImageFile.LOAD_TRUNCATED_IMAGES = True
# ^ Avoids issue #14 (GIMP images with
# "Raw profile type exif"), and image is displayed
# (often image isn't really broken,
# such as if saved with GIMP)


# from channeltinker import diff_images


Expand Down
10 changes: 9 additions & 1 deletion channeltinkerpil/findbyappearance.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@
sys.stderr.flush()
sys.exit(1)

from PIL import Image
from PIL import Image, ImageFile
import PIL


ImageFile.LOAD_TRUNCATED_IMAGES = True
# ^ Avoids issue #14 (GIMP images with
# "Raw profile type exif"), and image is displayed
# (often image isn't really broken,
# such as if saved with GIMP)


results = []


Expand Down
9 changes: 8 additions & 1 deletion channeltinkerpil/imageprocessorframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@

try:
import PIL
from PIL import Image
from PIL import Image, ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True # Fix issue #14 GIMP-saved
except ModuleNotFoundError as ex:
print("{}".format(ex))
print()
Expand Down Expand Up @@ -905,10 +906,16 @@ def loadImage(self, path):
self.markBtn['state'] = tk.NORMAL
echo1('- loaded.')
except PIL.UnidentifiedImageError:
# Must be *really* corrupt if
# ImageFile.LOAD_TRUNCATED_IMAGES = True
# doesn't work.
# self.imageLabels[index].configure(image='')
echo0(prefix+"index={}".format(index))
self.imageErrorVars[index].set("unreadable")
err = "Error: unreadable image"
# err = "{}: {}".format(type(ex).__name__, ex)
# ^ str(ex) is long & contains path, but path
# will be shown anyway.
self.statusSV.set(err)
# return False, err
except Exception as ex:
Expand Down

0 comments on commit cc46d19

Please sign in to comment.