diff --git a/Image-Circulator/README.md b/Image-Circulator/README.md new file mode 100644 index 0000000..2e2e3d3 --- /dev/null +++ b/Image-Circulator/README.md @@ -0,0 +1,13 @@ +# 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` + +Or make the script executable. 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!')