Skip to content

Commit d864a1d

Browse files
authored
Merge pull request #1754 from singhchanmeet/resize
Image-Resizing
2 parents f8a43c6 + af40af5 commit d864a1d

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

Image-Resizing/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Image-Resizing
2+
3+
## 📝 Description
4+
* This Python script automatically resizes any image(s) to the desired dimensions (in Pixels) at the desired DPI
5+
6+
<br>
7+
8+
## ⚙️ How To Use
9+
```bash
10+
pip install -r requirements.txt
11+
```
12+
13+
* Then store all the images that you want to resize in 'images' folder.
14+
15+
* Run the resize.py file <br/>
16+
You will be prompted to enter the dimensions
17+
18+
* The resized images will then get stored in the 'resized-images' folder.
19+
20+
## Contributor
21+
22+
* <a href="github.com/singhchanmeet"> Chanmeet Singh </a>

Image-Resizing/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
opencv_python==4.7.0.72
2+
Pillow==9.4.0

Image-Resizing/resize.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import cv2
2+
import os
3+
from PIL import Image
4+
5+
# inputting dimensions (in Pixels) from user
6+
width = int(input("Enter Width in Pixels: "))
7+
height = int(input("Enter Height in Pixels: "))
8+
dimensions=(width,height)
9+
10+
# inputting Horizontal and Vertical resolutions
11+
horizontal_dpi = int(input("Enter Horizontal Dots Per Inches (DPI): "))
12+
vertical_dpi = int(input("Enter Vertical Dots Per Inches (DPI): "))
13+
14+
# for each file in the images folder
15+
for filename in os.listdir('images'):
16+
img = cv2.imread(os.path.join('images', filename))
17+
# if the image is read successfully
18+
if img is not None:
19+
resized = cv2.resize(img, dimensions, interpolation=cv2.INTER_CUBIC)
20+
if resized is not None:
21+
cv2.imwrite(os.path.join('resized-images', filename), resized)
22+
im = Image.open(os.path.join('resized-images',filename))
23+
# if resizing is successful, now proceeding to DPI
24+
if im is not None:
25+
im.save(os.path.join('resized-images',filename), dpi=(horizontal_dpi, vertical_dpi))

0 commit comments

Comments
 (0)