Skip to content

Commit

Permalink
Fix #13: log image count NOT converted due to low-res
Browse files Browse the repository at this point in the history
1. Enable log if file not converted due to low-res
2. Show count of images not processed due to low-res
  • Loading branch information
jarun committed Apr 9, 2017
1 parent ac30556 commit 35c9066
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -160,8 +160,10 @@ Shell completion scripts for Bash, Fish and Zsh can be found in respective subdi

### Operational notes

- Multiple files and directories can be specified as source. If `PATH` is omitted, the current directory is processed.
- Output image names are appended with **_IMGP** if `--overwrite` option is not used. By default *_IMGP* files are not processed. Doing so may lead to potential race conditions when `--overwrite` option is used.
- PNG files with lower target hres/vres are not converted (even if `--convert` is used). Run `imgp --convert` to convert those.
- Resize and rotate are lossy operations. For additional reductions in size try `--optimize` and `--eraseexif` options.
- Output image names are appended with **_IMGP** if overwrite option is not used. By default *_IMGP* files are not processed. Doing so may lead to potential race conditions when `--overwrite` option is used.

## Examples

Expand Down
48 changes: 28 additions & 20 deletions imgp
Expand Up @@ -51,7 +51,8 @@ _VERSION_ = '2.2' # current program version
# Globals for multiprocessing
pool = None
lock = Lock()
count = 0
count = 0 # successful conversion count
count_lowres = 0 # no-op count due to low resolution


def getres(res):
Expand Down Expand Up @@ -80,10 +81,11 @@ def lock_print(msg):


def cb(data):
global count
global count, count_lowres

if data:
count += data
count += data[0]
count_lowres += data[1]


def traverse_dir(path):
Expand Down Expand Up @@ -173,7 +175,7 @@ def rotate_image(src):
if overwrite and converted:
os.remove(src)

return 1
return [1, 0]
except OSError as e:
with lock:
print(e)
Expand Down Expand Up @@ -247,9 +249,9 @@ def resize_image(src):
elif HRES == 0 or VRES == 0:
if HRES:
if not enlarge and HRES > hres:
if debug:
if not quiet:
lock_print('%s has lesser hres\n' % src)
return
return [0, 1]

hratio = HRES/float(hres)
target_vres = vres * hratio
Expand All @@ -263,9 +265,9 @@ def resize_image(src):

if VRES:
if not enlarge and VRES > vres:
if debug:
if not quiet:
lock_print('%s has lesser vres\n' % src)
return
return [0, 1]

vratio = VRES/float(vres)
target_hres = hres * vratio
Expand Down Expand Up @@ -293,9 +295,9 @@ def resize_image(src):
# same orientation (H >= V and h > v) or
# cross orientation (H < V and h >= v)
if not enlarge and HRES > hres:
if debug:
if not quiet:
lock_print('%s has lesser hres\n' % src)
return
return [0, 1]

if HRES != hres:
hratio = HRES/float(hres)
Expand All @@ -313,9 +315,9 @@ def resize_image(src):
# same orientation (H < V and h < v) or
# cross orientation (H >= V and h <= v)
if not enlarge and VRES > vres:
if debug:
if not quiet:
lock_print('%s has lesser vres\n' % src)
return
return [0, 1]

if VRES != vres:
vratio = VRES/float(vres)
Expand All @@ -334,9 +336,9 @@ def resize_image(src):

if ratio_img >= ratio_target:
if not enlarge and HRES > hres:
if debug:
if not quiet:
lock_print('%s has lesser hres\n' % src)
return
return [0, 1]

# re-sample as per target horizontal resolution
hratio = HRES/float(hres)
Expand All @@ -351,9 +353,9 @@ def resize_image(src):
% (HRES, target_vres))
else:
if not enlarge and VRES > vres:
if debug:
if not quiet:
lock_print('%s has lesser vres\n' % src)
return
return [0, 1]

# re-sample as per target vertical resolution
vratio = VRES/float(vres)
Expand Down Expand Up @@ -395,7 +397,7 @@ def resize_image(src):
if overwrite and converted:
os.remove(src)

return 1
return [1, 0]
except OSError as e:
with lock:
print(e)
Expand Down Expand Up @@ -566,9 +568,15 @@ def main():
pool.close()
pool.join()

if not quiet and count:
print('%s converted in %.4f seconds.'
% (count, time.time() - init_time))
if not quiet:
# Show number of images converted
if count:
print('%s processed in %.4f seconds.'
% (count, time.time() - init_time))

# Show number of images not ceonverted due to low resolution
if count_lowres:
print('%s not processed due to low resolution.' % count_lowres)

if __name__ == '__main__':
main()
14 changes: 10 additions & 4 deletions imgp.1
Expand Up @@ -20,10 +20,6 @@ is a multiprocessing command line image resizer and rotator for JPEG and PNG ima
* process directories recursively
* overwrite source image option
.PP
Multiple files and directories can be specified as source. If \fBPATH\fR is omitted, the current directory is processed.
.PP
Output image names are appended with \fB_IMGP\fR if overwrite option is not used. By default \fB_IMGP\fR files are not processed. Doing so may lead to potential race conditions when overwrite option is used.
.PP
.B Adaptive mode
.PP
- If the specified and image orientations are same [(H >= V and h > v) or (H < V and h < v)], the image is resized with the longer specified side as reference.
Expand All @@ -35,6 +31,16 @@ For example, if an image has a resolution of 2048x1365 and is being resized to 1
- In regular mode (default), output image resolution will be 1152x768
.br
- In adaptive mode, output image resolution will be 1366x910
.PP
.B Operational notes
.PP
- Multiple files and directories can be specified as source. If \fBPATH\fR is omitted, the current directory is processed.
.PP
- Output image names are appended with \fB_IMGP\fR if '--overwrite' option is not used. By default \fB_IMGP\fR files are not processed. Doing so may lead to potential race conditions when '--overwrite' option is used.
.PP
- PNG files with lower target hres/vres are not converted (even if '--convert' is used). Run 'imgp --convert' to convert those.
.PP
- Resize and rotate are lossy operations. For additional reductions in size try '--optimize' and '--eraseexif' options.
.SH OPTIONS
.TP
.BI "-h, --help"
Expand Down

0 comments on commit 35c9066

Please sign in to comment.