-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpillow_library.py
More file actions
executable file
·56 lines (41 loc) · 1.32 KB
/
pillow_library.py
File metadata and controls
executable file
·56 lines (41 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from PIL import Image , ImageFilter
image1 = Image.open('image.png')
image1.show()
#jpg to png
#image1.save('image.png')
#converting image png to jpg
with Image.open("image.png") as im:
# Set the mode to RGB
rgb_im = im.convert('RGB')
rgb_im.save('image1.jpg')
import os
#opening the fies with the same extensions and converting them into jpeg
for f in os.listdir('.'):
if f.endswith('.jpg'):
i = Image.open(f)
fn, text = os.path.splitext(f)
# print(fn)
# print(text)
i.save('pngs/{}.png'.format(fn)) #converting images to pngs
# Resizing the files
size_300 = (300, 300)
size_700 =(700,550) # for 700 pixels image
for f in os.listdir('.'):
if f.endswith('.jpg'):
i = Image.open(f)
fn, fext = os.path.splitext(f)
# print(fn)
# print(fext)
i.thumbnail(size_300) #takes size in tuples
i.save('pngs/{}_300{}'.format(fn,fext)) #fn is filename_300.jpg(fext)
i.thumbnail(size_700) #takes size in tuples
i.save('pngs/{}_700{}'.format(fn,fext))
#Roatate the iage
image2 = Image.open('sachitanand_sign.jpg')
image2.rotate(90).save('image90.jpg')
#to convert in the BW image
image2.convert(mode='L')
image2.show()
#Blur the image , by Imagefilter
image2.filter(ImageFilter.GaussianBlur(15))
image2.show()