diff --git a/changelog.txt b/changelog.txt index 55a3e96..6fe2050 100644 --- a/changelog.txt +++ b/changelog.txt @@ -4,6 +4,16 @@ Version history: ================ +--- +v.1.3.1 - 03-05-2019 + * Fixed a PermissionError that would occur when trying to optimize a single + image in the current directory without explicitly specifying its path. + * Added basic Exception handling for piexif related instructions. This is a + temporary solution that should silence, for now, some errors related to + issue #3 but we should still check if we can provide a more specific + treatment for those piexif exceptions. We still have a few TODO items + related to issue #3. Let's hope they can be addressed in the next release. + --- v.1.3 - 10-10-2018 * Added dynamic (variable) JPG quality setting. diff --git a/optimize_images/__init__.py b/optimize_images/__init__.py index eae1c3a..7267bef 100755 --- a/optimize_images/__init__.py +++ b/optimize_images/__init__.py @@ -1 +1 @@ -__version__ = '1.3' \ No newline at end of file +__version__ = '1.3.1' \ No newline at end of file diff --git a/optimize_images/__main__.py b/optimize_images/__main__.py index da0e293..c7afd8f 100644 --- a/optimize_images/__main__.py +++ b/optimize_images/__main__.py @@ -55,8 +55,12 @@ def do_optimization(t: Task) -> TaskResult: :param t: A Task object containing all the parameters for the image processing. :return: A TaskResult object containing information for single file report. """ + # TODO: Catch exceptions that may occur here. img = Image.open(t.src_path) + # TODO: improve method of image format detection (what should happen if the + # file extension does not match the image content's format? Maybe we + # should skip unsupported formats?) if img.format.upper() == 'PNG': return optimize_png(t) # elif img.format.upper() == 'JPEG': diff --git a/optimize_images/img_optimize_jpg.py b/optimize_images/img_optimize_jpg.py index 02d287b..cc88ffb 100644 --- a/optimize_images/img_optimize_jpg.py +++ b/optimize_images/img_optimize_jpg.py @@ -34,6 +34,10 @@ def optimize_jpg(t: Task) -> TaskResult: orig_mode = img.mode folder, filename = os.path.split(t.src_path) + + if folder == '': + folder = os.getcwd() + temp_file_path = os.path.join(folder + "/~temp~" + filename) orig_size = os.path.getsize(t.src_path) orig_colors, final_colors = 0, 0 @@ -45,6 +49,9 @@ def optimize_jpg(t: Task) -> TaskResult: had_exif = False except ValueError: # No exif info had_exif = False + # TODO: Check if we can provide a more specific treatment of piexif exceptions. + except Exception: + had_exif = False if t.max_w or t.max_h: img, was_downsized = downsize_img(img, t.max_w, t.max_h) @@ -85,6 +92,9 @@ def optimize_jpg(t: Task) -> TaskResult: has_exif = True except ValueError: has_exif = False + # TODO: Check if we can provide a more specific treatment of piexif exceptions. + except Exception: + had_exif = False else: has_exif = False