Skip to content

Instantly share code, notes, and snippets.

@squamous
Last active August 9, 2016 14:40
Show Gist options
  • Select an option

  • Save squamous/bee9d1d50b4d51311c6af0abe58bba59 to your computer and use it in GitHub Desktop.

Select an option

Save squamous/bee9d1d50b4d51311c6af0abe58bba59 to your computer and use it in GitHub Desktop.

Revisions

  1. squamous revised this gist Aug 9, 2016. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions image_resize.py
    Original file line number Diff line number Diff line change
    @@ -6,18 +6,18 @@
    from PIL import Image


    def perc(num, perc):
    return (float(perc) / 100) * float(num)

    if __name__ == '__main__':
    if len(sys.argv) > 2:
    percentage = sys.argv[1]
    print 'Resizing each image by %s%%' % percentage
    percentage = int(sys.argv[1]) / float(100)
    print 'Resizing each image by %s%%' % (percentage * 100)
    imgs = sys.argv[2:]
    for fname in imgs:
    img = Image.open(fname)
    w, h = img.size
    img = img.resize((perc(w, percentage), perc(h, percentage)), Image.BILINEAR)
    img = img.resize(
    (int(w * percentage), int(h * percentage)),
    Image.BILINEAR
    )
    img.save("resize_%s" % fname)
    else:
    print '%s <percentage> [file ...]' % os.path.basename(sys.argv[0])
  2. squamous revised this gist Aug 9, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion image_resize.py
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,8 @@
    #
    # Resize a set of images by a given percentage.

    import sys, os, Image
    import sys, os
    from PIL import Image


    def perc(num, perc):
  3. squamous created this gist Jul 29, 2016.
    22 changes: 22 additions & 0 deletions image_resize.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/usr/bin/env python
    #
    # Resize a set of images by a given percentage.

    import sys, os, Image


    def perc(num, perc):
    return (float(perc) / 100) * float(num)

    if __name__ == '__main__':
    if len(sys.argv) > 2:
    percentage = sys.argv[1]
    print 'Resizing each image by %s%%' % percentage
    imgs = sys.argv[2:]
    for fname in imgs:
    img = Image.open(fname)
    w, h = img.size
    img = img.resize((perc(w, percentage), perc(h, percentage)), Image.BILINEAR)
    img.save("resize_%s" % fname)
    else:
    print '%s <percentage> [file ...]' % os.path.basename(sys.argv[0])