Skip to content

Commit 65d6b8c

Browse files
Merge pull request #284 from Sapna2001/crop_image
Circular Image
2 parents 3f9fb6a + 544046d commit 65d6b8c

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

Python/Circular_Image/Readme.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Circular Image
2+
3+
This script provides a circular image when a regular image is given.
4+
5+
## Requirement for this script:
6+
7+
1. numpy
8+
2. PIL
9+
10+
install it by running the following commands in the command prompt:
11+
12+
1. pip install numpy
13+
2. pip install pillow
14+
15+
## How to use this script?
16+
17+
Just type the following in your command prompt:
18+
19+
python script.py
20+
21+
## Sample of the script in action:
22+
23+
This is the original picture.</br></br>
24+
<img src="./sunflower.jpg" alt="Original Image"></br>
25+
26+
![demo](https://user-images.githubusercontent.com/56690856/98395315-13812480-2082-11eb-9c28-6ee31e0fa037.png)</br>
27+
28+
Circular Image will be created in the directory with the file name : circularImg.png</br></br>
29+
<img src="./circularImg.png" alt="Original Image">
30+

Python/Circular_Image/circularImg.png

178 KB
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
numpy
2+
PIL

Python/Circular_Image/script.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import numpy as np
2+
from PIL import Image, ImageDraw
3+
4+
# Enter the diameter
5+
diameter = input("Enter the diameter:")
6+
7+
# Open the input image as numpy array after resizing it, and then convert to RGB
8+
img=Image.open("sunflower.jpg").convert("RGB")
9+
modifiedSize = int(diameter);
10+
img = img.resize((modifiedSize,modifiedSize));
11+
npImage=np.array(img)
12+
width, height = img.size
13+
14+
# Create same size alpha layer with circle
15+
alpha = Image.new('L', img.size,0)
16+
draw = ImageDraw.Draw(alpha)
17+
draw.pieslice([0,0,height,width],0,360,fill=255)
18+
19+
# Convert alpha Image to numpy array
20+
npAlpha=np.array(alpha)
21+
22+
# Add alpha layer to RGB
23+
npImage=np.dstack((npImage,npAlpha))
24+
25+
# Save with alpha and then save it has circularImg.png
26+
Image.fromarray(npImage).save('circularImg.png')

Python/Circular_Image/sunflower.jpg

133 KB
Loading

0 commit comments

Comments
 (0)