File tree Expand file tree Collapse file tree 4 files changed +33
-0
lines changed Expand file tree Collapse file tree 4 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Compress Image
2
+
3
+ ## Description
4
+ This snippet of code will convert any image to grayscale.
5
+
6
+ ## Requirements
7
+
8
+ ` $ pip install Pillow `
9
+
10
+ ## Steps To Execution
11
+ - Fork this repo and navigate to ShortenLinks folder
12
+ - (optional) Add images to same directory with this ` code.py ` file.
13
+ - Modify the image name in ` code.py ` GrayScaled_YOURIMGNAME.jpg".
14
+
15
+ ## Output
16
+
17
+
18
+ | Before | After |
19
+ | :---:| :---------------------------------------------------------------------------------------------------------------------:|
20
+ | ![ 1] ( https://user-images.githubusercontent.com/52918207/121647416-0151e380-cab4-11eb-96d1-1dfd127789c6.jpg ) | ![ 1_compressed] ( https://user-images.githubusercontent.com/52918207/121647438-06af2e00-cab4-11eb-9fa5-b84787163bb2.jpg ) |
21
+ | Colourful | GrayScaled |
22
+
Original file line number Diff line number Diff line change
1
+ from PIL import Image
2
+ from os import listdir ,getcwd
3
+ from os .path import isfile , join
4
+
5
+ onlyfiles = [f for f in listdir (getcwd ()) if isfile (join (getcwd (), f ))]
6
+ print ("All files in current dir :" ,onlyfiles )
7
+
8
+ img = Image .open (input ("Enter image filename : " )) # image name with relative path
9
+ grayscale = img .convert ('L' )
10
+ grayscale .save ('GrayScaled_{}' .format (img .filename ))
11
+
You can’t perform that action at this time.
0 commit comments