diff --git a/aidesign_blend/libs/blenders.py b/aidesign_blend/libs/blenders.py index e8d8a06..eb38b17 100644 --- a/aidesign_blend/libs/blenders.py +++ b/aidesign_blend/libs/blenders.py @@ -6,7 +6,6 @@ # Last updated by username: liu-yucheng import datetime -import imghdr import numpy import os import pathlib @@ -26,7 +25,6 @@ _BlenderContext = contexts.BlenderContext _Callable = typing.Callable _clamp = utils.clamp_float -_isfile = ospath.isfile _join = ospath.join _listdir = os.listdir _load_json = utils.load_json @@ -50,7 +48,6 @@ _save_text = utils.save_text _seed = random.seed _shuffle = random.shuffle -_what = imghdr.what # End @@ -364,6 +361,13 @@ def _parse_config(self): self.logln("Completed parsing blenders config", 1) + def _tweak_pil_safety(self): + max_width = 65535 + max_height = 65535 + max_pixels = max_width * max_height + pil_image.MAX_IMAGE_PIXELS = max_pixels + self.logln(f"Tweaked PIL safety max pixels: Width: {max_width} Height: {max_height} Total: {max_pixels}", 1) + def _read_frags_path(self, frags_path): frag_names = _listdir(frags_path) frag_names.sort() @@ -378,10 +382,16 @@ def _read_frags_path(self, frags_path): frag_locs = [] for loc in orig_frag_locs: - is_file = _isfile(loc) - is_img = is_file and _what(loc) is not None + try: + image = _pil_image_open(loc) + image_format = image.format + except Exception as _: + image_format = None + # end try - if is_img: + is_image = image_format is not None + + if is_image: frag_locs.append(loc) # end for @@ -688,13 +698,6 @@ def _prep_frags_grid(self): self.logln(f"Prepared the fragments grid: Width: {width} Height: {height}", 1) # end if - def _tweak_pil_safety(self): - max_width = 65535 - max_height = 65535 - max_pixels = max_width * max_height - pil_image.MAX_IMAGE_PIXELS = max_pixels - self.logln(f"Tweaked PIL safety max pixels: Width: {max_width} Height: {max_height} Total: {max_pixels}", 1) - def _blend_block(self, block_y, block_x): c = self._context @@ -1123,11 +1126,11 @@ def prep(self): self.logln(info) self._read_config() self._parse_config() + self._tweak_pil_safety() self._prep_frags() self._prep_matrices() self._prep_canvas() self._prep_frags_grid() - self._tweak_pil_safety() info = str( "-\n" diff --git a/setup.py b/setup.py index 75f3dd1..d43b91b 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ def main(): """Main function.""" _setup( name="aidesign-blend", - version="1.7.2", + version="1.7.3", author="Yucheng Liu (From The AIDesign Team)", license="Copyright (C) 2022 Yucheng Liu. GNU GPL3 license.", description="AIDesign image fragments blending application.",