Skip to content

Commit

Permalink
option --nn for PNG nearest neighbour
Browse files Browse the repository at this point in the history
  • Loading branch information
jarun committed Feb 15, 2018
1 parent fc75bf5 commit 4b5979e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ optional arguments:
specified hres or vres or --res=100 [default: off]
-m, --mute operate silently [default: informative]
-n, --enlarge enlarge smaller images [default: off]
--nn use nearest neighbour interpolation for PNG images
[default: antialias]
-p, --optimize optimize the output images [default: off]
-q N, --quality N quality factor (N=1-95, JPEG only) [default: 75]
-r, --recurse process directories recursively [default: off]
Expand Down
1 change: 1 addition & 0 deletions auto-completion/bash/imgp-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ _imgp () {
-k --keep
-m --mute
-n --enlarge
--nn
-o --rotate
-p --optimize
-q --quality
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 @@ -14,6 +14,7 @@ complete -c imgp -s i -l includeimgp --description 're-process _IMGP files'
complete -c imgp -s k -l keep --description 'skip images with matching hres or vres'
complete -c imgp -s m -l mute --description 'operate silently'
complete -c imgp -s n -l enlarge --description 'enlarge smaller images'
complete -c imgp -l nn --description 'use nearest neighbour interpolation for PNG'
complete -c imgp -s o -l rotate -r --description 'rotate clockwise by angle (in degrees)'
complete -c imgp -s p -l optimize --description 'optimize the output images'
complete -c imgp -s q -l quality -r --description 'specify quality factor (1-95)'
Expand Down
1 change: 1 addition & 0 deletions auto-completion/zsh/_imgp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ args=(
'(-k --keep)'{-k,--keep}'[skip images with matching hres or vres]'
'(-m --mute)'{-m,--mute}'[operate silently]'
'(-n --enlarge)'{-n,--enlarge}'[enlarge smaller images]'
'(--nn)--n[use nearest neighbour interpolation for PNG]'
'(-o --rotate)'{-o,--rotate}'[rotate clockwise by angle]:degree'
'(-p --optimize)'{-p,--optimize}'[optimize the output images]'
'(-q --quiet)'{-q,--quality}'[specify quality factor (1-95)]:factor'
Expand Down
13 changes: 7 additions & 6 deletions imgp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ overwrite = False # remove source images
debug = False # enable debug information
no_res_opt = False # --res is not specified
pad = '_IMGP' # output file suffix when --overwrite is unused
nn_png = False # if the image is a png, use nearest neighbour interpolation
png_ip = PIL.Image.ANTIALIAS # default interpolation for PNG
fill_color = '#ffffff' # BG color to strip alpha channel
init_time = time.time() # profile the total time taken
_VERSION_ = '2.4.1' # current program version
Expand Down Expand Up @@ -231,7 +231,7 @@ def resize_image(src):
vres = img.size[1]
ImageFile.MAXBLOCK = hres * vres

antialias = PIL.Image.NEAREST if nn_png and _format == 'PNG' else PIL.Image.ANTIALIAS
antialias = png_ip if _format == 'PNG' else PIL.Image.ANTIALIAS
if keep and (HRES == hres or VRES == vres or scale == 100):
if not (_format == 'PNG' and convert):
return
Expand Down Expand Up @@ -466,8 +466,8 @@ def parse_args(args=None, namespace=None):
help='operate silently [default: informative]')
addarg('-n', '--enlarge', action='store_true',
help='enlarge smaller images [default: off]')
addarg('-nn', action='store_true',
help='use nearest neighbour interpolation for PNG images [default: off]')
addarg('--nn', action='store_true',
help='use nearest neighbour interpolation for PNG images [default: antialias]')
addarg('-p', '--optimize', action='store_true',
help='optimize the output images [default: off]')
addarg('-q', '--quality', type=int, metavar='N', choices=range(1, 96),
Expand All @@ -494,7 +494,7 @@ def parse_args(args=None, namespace=None):

def main():
global HRES, VRES, scale, rotate, adapt, convert, dot, eraseexif, force, includeimgp, keep, enlarge, \
optimal, mute, recurse, size, qual, overwrite, debug, no_res_opt, pool, init_time, count, nn_png
optimal, mute, recurse, size, qual, overwrite, debug, no_res_opt, pool, init_time, count, png_ip

args = parse_args()

Expand Down Expand Up @@ -554,7 +554,8 @@ def main():
qual = args.quality
overwrite = args.overwrite
debug = args.debug
nn_png = args.nearest_neighbour
if args.nn:
png_ip = PIL.Image.NEAREST

pool = Pool()

Expand Down
3 changes: 3 additions & 0 deletions imgp.1
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ Do not process if image hres or vres matches specified hres or vres, or --res is
.BI "-n, --enlarge"
Enlarge smaller images. By default smaller images are not scaled if specified resolution is greater.
.TP
.BI "--nn"
Use nearest neighbour interpolation for PNG images instead of default antialias.
.TP
.BI "-p, --optimize"
Optimize output images using PIL library optimization algorithm. Disabled by default.
.TP
Expand Down

2 comments on commit 4b5979e

@sinjax
Copy link
Contributor

@sinjax sinjax commented on 4b5979e Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@jarun
Copy link
Owner Author

@jarun jarun commented on 4b5979e Feb 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Did you test and confirm it works?

Please sign in to comment.