Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4ffbce

Browse files
authored
Merge pull request hastagAB#48 from nitish-iiitd/master
Added Color_to_BW_Converter
2 parents c81437e + 640a146 commit a4ffbce

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Color_to_BW_Converter/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Colored Image to Black & White Image Converter
2+
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.
3+
4+
## Libraries Required
5+
1. Pillow (PIL)
6+
`$pip install Pillow`
7+
8+
## Usage
9+
1. Go to the script's folder and open command prompt.
10+
2. Run command : `$python bw_convert.py <image_file_name>`
11+
12+
## Example
13+
`$python bw_convert.py sample_image.jpg`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import sys
2+
from PIL import Image
3+
from PIL.ExifTags import TAGS
4+
5+
image_file = sys.argv[1]
6+
image_name = image_file.split(".")[0]
7+
8+
try:
9+
image = Image.open(image_file)
10+
except IOError:
11+
print("Error in loading image!!")
12+
sys.exit(1)
13+
14+
bw_image = image.convert('L')
15+
bw_image.save("bw_"+image_name+".png")
143 KB
Loading

0 commit comments

Comments
 (0)