Skip to content

Commit a40b3fa

Browse files
authored
Added Round Corner Image Function
1 parent 1d76738 commit a40b3fa

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

image_rounded_corner/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
USER GUIDE
2+
Setup and activate virtual environment :
3+
4+
For Unix based systems please execute the following command to create venv and install requirements.
5+
6+
make init
7+
source .venv/bin/activate
8+
9+
Pre-requisites
10+
11+
1) Python pillow
12+
$ pip install pillow
13+
14+
How to run the script?
15+
16+
Please the edit the script with the source file location and the destination file location of the photo to be used.
17+
Run the python script
18+
19+
$ python rounded_corner.py
20+
21+
Once done, the script will produce with the resultant image.

image_rounded_corner/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pillow
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from PIL import Image, ImageDraw
2+
3+
4+
def add_corners(im, rad):
5+
circle = Image.new('L', (rad * 2, rad * 2), 0)
6+
draw = ImageDraw.Draw(circle)
7+
draw.ellipse((0, 0, rad * 2, rad * 2), fill=255)
8+
alpha = Image.new('L', im.size, 255)
9+
w, h = im.size
10+
alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0))
11+
alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad))
12+
alpha.paste(circle.crop((rad, 0, rad * 2, rad)), (w - rad, 0))
13+
alpha.paste(circle.crop((rad, rad, rad * 2, rad * 2)), (w - rad, h - rad))
14+
im.putalpha(alpha)
15+
return im
16+
17+
im = Image.open('Location_to_image/image.png')
18+
im = add_corners(im, 100)
19+
im.save('Location_to_store/img_rounded.png')

0 commit comments

Comments
 (0)