code to resize images

This commit is contained in:
lordvader501 2022-10-05 10:40:16 +05:30
parent 2233f1aa13
commit a3ee524156
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,21 @@
# IMAGE RESIZER
### Resize image to partiular dimensions.
This python code takes image that needs to be resised and it uses Pillow module to resize the image by given dimensions entered by user and saves the resized image.
#### Requirements:
* Install Pillow module.
* run `pip install pillow`
### Usage
* Clone the repo
* open the `Image-resizer` folder
* copy the image that you want to resize to this folder
* open cmd in `image-resizer` folder
##### for windows
* run `python resize.py`
##### for linux
* run `python3 resize.py`
* after that type the name of the image file in images folder (ex: img.jpg, pic.png...)
* enter the dimensions in the format(eg 1024x720 , 600x300...)
* now your resized image is saved in folder.

View File

@ -0,0 +1,11 @@
from PIL import Image as img
import os
file_name = input("Enter anpe of file: ")
name , ext = file_name.split('.')
pic = img.open((os.path.join(os.path.dirname(os.path.abspath(__file__)),file_name)))
ht, wt= input("Enter dimenstions(eg: 1024x720): ").split('x')
dim = int(ht), int(wt)
img_resize = pic.resize(dim)
img_resize.save((os.path.join(os.path.dirname(os.path.abspath(__file__)),f'{name}_resized.{ext}')))