From 4d78cc9f1a04605a044db46a56abb8fbc27df64c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 11 Dec 2015 18:38:45 +0530 Subject: [PATCH] Image compression: If the compression tools return a zero byte image ignore it and use the original image --- src/calibre/utils/img.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/calibre/utils/img.py b/src/calibre/utils/img.py index 5a1426505d..e94c192312 100644 --- a/src/calibre/utils/img.py +++ b/src/calibre/utils/img.py @@ -105,6 +105,12 @@ def run_optimizer(file_path, cmd, as_filter=False, input_data=None): if p.wait() != 0: return raw else: + try: + sz = os.path.getsize(outfile) + except EnvironmentError: + sz = 0 + if sz < 1: + return raw shutil.copystat(file_path, outfile) atomic_rename(outfile, file_path) finally: