mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Added Color_to_BW_Converter
This commit is contained in:
parent
80c46d29d2
commit
640a146249
13
Color_to_BW_Converter/README.md
Normal file
13
Color_to_BW_Converter/README.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Colored Image to Black & White Image Converter
|
||||
A simple python script which takes colored image filename as argument and converts it into grayscale image and saves the output image file. It shows the basic usage of Pillow library.
|
||||
|
||||
## Libraries Required
|
||||
1. Pillow (PIL)
|
||||
`$pip install Pillow`
|
||||
|
||||
## Usage
|
||||
1. Go to the script's folder and open command prompt.
|
||||
2. Run command : `$python bw_convert.py <image_file_name>`
|
||||
|
||||
## Example
|
||||
`$python bw_convert.py sample_image.jpg`
|
15
Color_to_BW_Converter/bw_convert.py
Normal file
15
Color_to_BW_Converter/bw_convert.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
import sys
|
||||
from PIL import Image
|
||||
from PIL.ExifTags import TAGS
|
||||
|
||||
image_file = sys.argv[1]
|
||||
image_name = image_file.split(".")[0]
|
||||
|
||||
try:
|
||||
image = Image.open(image_file)
|
||||
except IOError:
|
||||
print("Error in loading image!!")
|
||||
sys.exit(1)
|
||||
|
||||
bw_image = image.convert('L')
|
||||
bw_image.save("bw_"+image_name+".png")
|
BIN
Color_to_BW_Converter/sample_image.jpg
Normal file
BIN
Color_to_BW_Converter/sample_image.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 143 KiB |
Loading…
Reference in New Issue
Block a user