Image Grayscalling

Image GrayScalling

Description

This snippet of code will convert any colourful image to grayscale.

Requirements

$ pip install Pillow

Steps To Execution

  • Fork this repo and navigate to ShortenLinks folder
  • (optional) Add images to same directory with this code.py file.
  • Enter image name in input.
  • Boom!! you will see a image will generate with name as GrayScaled_YOURIMGNAME.jpg”.

Output

Before After
1 1_GrayScaled
Colourful GrayScaled

Source Code: code.py

from PIL import Image
from os import listdir,getcwd
from os.path import isfile, join

onlyfiles = [f for f in listdir(getcwd()) if isfile(join(getcwd(), f))]
print("All files in current dir :",onlyfiles)

img = Image.open(input("Enter image filename : "))  # image name with relative path
grayscale = img.convert('L')
grayscale.save('GrayScaled_{}'.format(img.filename))