Skip to content

Commit

Permalink
Limit processing by minimum image size
Browse files Browse the repository at this point in the history
  • Loading branch information
jarun committed Apr 9, 2017
1 parent 35c9066 commit 59751f4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Powered by an intelligent adaptive algorithm, recursive operations, multiprocess
- adaptive resize considering orientation
- brute force to a resolution
- optimize images to save more space
- limit processing by minimum image size
- convert PNG to JPEG
- erase exif metadata
- force smaller to larger resize
Expand Down Expand Up @@ -155,6 +156,7 @@ Shell completion scripts for Bash, Fish and Zsh can be found in respective subdi
-q, --quiet operate silently [default: verbose]
-r, --recursive process directories recursively [default: off]
symbolic links to directories are ignored
-s byte, --size byte minimum size to process an image [default: 1024]
-w, --overwrite overwrite source images [default: off]
-z, --debug enable debug logs [default: off]

Expand Down
4 changes: 2 additions & 2 deletions auto-completion/bash/imgp-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ _imgp () {
local -a opts opts_with_args
opts=(-a --adapt -c --convert -d --dot -e --eraseexif -f --force -h --help
-i --includeimgp -k --keep -n --enlarge -o --rotate -p --optimize
-q --quiet -r --recurse -w --overwrite -x --res -z --debug)
opts_with_arg=(-o --rotate -x --res)
-q --quiet -r --recurse -s --size -w --overwrite -x --res -z --debug)
opts_with_arg=(-o --rotate -s --size -x --res)

# Do not complete non option names
[[ $cur == -* ]] || return 1
Expand Down
1 change: 1 addition & 0 deletions auto-completion/fish/imgp.fish
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ complete -c imgp -s o -l rotate -r --description 'rotate clockwise by angle (i
complete -c imgp -s p -l optimize --description 'optimize the output images'
complete -c imgp -s q -l quiet --description 'operate silently'
complete -c imgp -s r -l recurse --description 'process directories recursively'
complete -c imgp -s s -l size -r --description 'min byte size to process an image'
complete -c imgp -s w -l overwrite --description 'overwrite source images'
complete -c imgp -s x -l res -r --description 'output resolution in HxV or %'
complete -c imgp -s z -l debug --description 'enable debug logs'
1 change: 1 addition & 0 deletions auto-completion/zsh/_imgp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ args=(
'(-p --optimize)'{-o,--optimize}'[optimize the output images]'
'(-q --quiet)'{-q,--quiet}'[operate silently]'
'(-r --recurse)'{-r,--recurse}'[process directories recursively]'
'(-s --size)'{-r,--size}'[min byte size to process an image]:bytes'
'(-w --overwrite)'{-w,--overwrite}'[overwrite source images]'
'(-x --res)'{-x,--res}'[output resolution]:HxV or %'
'(-z --debug)'{-z,--debug}'[enable debug logs]'
Expand Down
21 changes: 15 additions & 6 deletions imgp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enlarge = False # enlarge images with smaller hres or vres
optimize = False # apply PIL library optimization when saving
quiet = False # suppress additional information
recurse = False # recursively process subdirectories
size = 1024 # min byte size to process an image
overwrite = False # remove source images
debug = False # enable debug information
no_res_opt = False # --res is not specified
Expand Down Expand Up @@ -105,10 +106,14 @@ def traverse_dir(path):
lock_print(entry.path + ': no permission')
continue
traverse_dir(entry.path)
elif rotate is not None:
pool.apply_async(rotate_image, args=(entry.path,), callback=cb)
else:
pool.apply_async(resize_image, args=(entry.path,), callback=cb)
elif (entry.is_file(follow_symlinks=False) and
entry.stat().st_size >= size):
if rotate is not None:
pool.apply_async(rotate_image, args=(entry.path,),
callback=cb)
else:
pool.apply_async(resize_image, args=(entry.path,),
callback=cb)
except OSError as e:
with lock:
print(e)
Expand Down Expand Up @@ -470,6 +475,8 @@ def parse_args(args=None, namespace=None):
addarg('-r', '--recurse', action='store_true',
help='process directories recursively [default: off] \
symbolic links to directories are ignored')
addarg('-s', '--size', type=int, metavar='byte',
help='minimum size to process an image [default: 1024]')
addarg('-w', '--overwrite', action='store_true',
help='overwrite source images [default: off]')
addarg('-z', '--debug', action='store_true',
Expand All @@ -488,7 +495,7 @@ def parse_args(args=None, namespace=None):
def main():
global HRES, VRES, scale, rotate, adapt, convert, dot, eraseexif, \
force, includeimgp, keep, enlarge, optimize, quiet, recurse, \
overwrite, debug, no_res_opt, pool, init_time, count
size, overwrite, debug, no_res_opt, pool, init_time, count

args = parse_args()

Expand Down Expand Up @@ -542,6 +549,8 @@ def main():
optimize = args.optimize
quiet = args.quiet
recurse = args.recurse
if args.size is not None:
size = args.size
overwrite = args.overwrite
debug = args.debug

Expand Down Expand Up @@ -574,7 +583,7 @@ def main():
print('%s processed in %.4f seconds.'
% (count, time.time() - init_time))

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

Expand Down
4 changes: 4 additions & 0 deletions imgp.1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ is a multiprocessing command line image resizer and rotator for JPEG and PNG ima
* adaptive resize considering orientation
* brute force to a resolution
* optimize images to save more space
* limit processing by minimum image size
* convert PNG to JPEG
* erase exif metadata
* force smaller to larger resize
Expand Down Expand Up @@ -85,6 +86,9 @@ Do not show any operational output.
.B "-r, --recursive"
Recursively process sub-directories. By default only the specified directory is processed. Symbolic links to directories are ignored to avoid recursive loops.
.TP
.B "-s, --recursive=" byte
Minimum size in bytes required to process an image. Acts as a guard against processing low-resolution images. Default 1024 bytes.
.TP
.BI "-w, --overwrite"
Overwrite the source images. By default an output image is saved with \fB_IMGP\fR appended to the source image name.
.br
Expand Down

0 comments on commit 59751f4

Please sign in to comment.