mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-23 20:11:10 +00:00
code to resize images
This commit is contained in:
parent
2233f1aa13
commit
a3ee524156
21
scripts/Image_resizer/readme.md
Normal file
21
scripts/Image_resizer/readme.md
Normal 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.
|
11
scripts/Image_resizer/resize.py
Normal file
11
scripts/Image_resizer/resize.py
Normal 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}')))
|
Loading…
Reference in New Issue
Block a user