From e34cd220c6f2808599fe1bcbd6b581eff19d6517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berk=20G=C3=BCreken?= Date: Wed, 3 Oct 2018 04:28:29 +0300 Subject: [PATCH 1/3] Add python script for making images circular. --- Image-Circulator/README.md | 12 ++++++++ Image-Circulator/image_circulator.py | 41 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Image-Circulator/README.md create mode 100644 Image-Circulator/image_circulator.py diff --git a/Image-Circulator/README.md b/Image-Circulator/README.md new file mode 100644 index 0000000..30e687e --- /dev/null +++ b/Image-Circulator/README.md @@ -0,0 +1,12 @@ +# Image Circulator +Tiny Python3 script to make your images circular. + +##Dependencies + It requires `python3` and `pillow`. + To install `pillow`, you need `pip3` or python3. + +## Usage +To run, from the command line type: + +`python3 image_circulator.py -i INPUT_FILE_PATH -o OUTPUT_FILE_PATH -d DIAMETER_IN_PIXELS` + diff --git a/Image-Circulator/image_circulator.py b/Image-Circulator/image_circulator.py new file mode 100644 index 0000000..fb0cb23 --- /dev/null +++ b/Image-Circulator/image_circulator.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +from PIL import Image, ImageOps, ImageDraw +from argparse import ArgumentParser + + +parser = ArgumentParser() +inputfile = parser.add_argument('-i', '--inputfile', help='input file path') +outputfile = parser.add_argument('-o', '--outputfile', help='output file path') +diameter = parser.add_argument('-d', '--diameter', help='output file diameter') + +args = parser.parse_args() + + +print('Input file is '+ str(args.inputfile)) +print('Output file is '+ str(args.outputfile)) +print('Image diameter will be '+ str(args.diameter)) + +im = Image.open(args.inputfile) + +width, height = im.size + +left = (width - int(args.diameter))/2 +top = (height - int(args.diameter))/2 +right = (width + int(args.diameter))/2 +bottom = (height + int(args.diameter))/2 + +im = im.crop((left, top, right, bottom)); + +bigsize = (im.size[0] * 3, im.size[1] * 3) +mask = Image.new('L', bigsize, 0) +draw = ImageDraw.Draw(mask) +draw.ellipse((0, 0) + bigsize, fill=255) +mask = mask.resize(im.size, Image.ANTIALIAS) +im.putalpha(mask) + +output = ImageOps.fit(im, mask.size, centering=(0.5, 0.5)) +output.putalpha(mask) +output.save(args.outputfile) + +print('Done!') From a699b405c9b029b06e066f8f319a4034640e3f2c Mon Sep 17 00:00:00 2001 From: Berk Gureken Date: Wed, 3 Oct 2018 04:29:43 +0300 Subject: [PATCH 2/3] Update README.md --- Image-Circulator/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Image-Circulator/README.md b/Image-Circulator/README.md index 30e687e..407a45e 100644 --- a/Image-Circulator/README.md +++ b/Image-Circulator/README.md @@ -1,7 +1,7 @@ # Image Circulator Tiny Python3 script to make your images circular. -##Dependencies +## Dependencies It requires `python3` and `pillow`. To install `pillow`, you need `pip3` or python3. From a8a37f92fe7f8a06bb04508fff090f441a4640a2 Mon Sep 17 00:00:00 2001 From: Berk Gureken Date: Wed, 3 Oct 2018 04:31:17 +0300 Subject: [PATCH 3/3] Update README.md --- Image-Circulator/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Image-Circulator/README.md b/Image-Circulator/README.md index 407a45e..2e2e3d3 100644 --- a/Image-Circulator/README.md +++ b/Image-Circulator/README.md @@ -10,3 +10,4 @@ To run, from the command line type: `python3 image_circulator.py -i INPUT_FILE_PATH -o OUTPUT_FILE_PATH -d DIAMETER_IN_PIXELS` +Or make the script executable.