Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
victordomingos committed May 3, 2019
1 parent bf31aba commit ad0aee7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
10 changes: 10 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion optimize_images/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3'
__version__ = '1.3.1'
4 changes: 4 additions & 0 deletions optimize_images/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
10 changes: 10 additions & 0 deletions optimize_images/img_optimize_jpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ad0aee7

Please sign in to comment.