Python - Image Manipulation with Pillow
** Image Manipulation with Pillow
==========================================
from PIL import Image
image1 = Image.open('girl1.jpg')
image1.show()
---------------------------------
---------------------------------
==========================================
from PIL import Image
image1 = Image.open('apple1.jpg')
image1.save('apple1.png')
---------------------------------
---------------------------------
==========================================
from PIL import Image
import os
for f in os.listdir('.'):
if f.endswith('.jpg'):
print(f)
---------------------------------
apple1.jpg
apple2.jpg
apple3.jpg
apple4.jpg
---------------------------------
==========================================
from PIL import Image
import os
for f in os.listdir('.'):
if f.endswith('.jpg'):
i = Image.open(f)
fn, fext = os.path.splitext(f)
i.save('pngs/{}.png'.format(fn))
---------------------------------
---------------------------------
==========================================
from PIL import Image
import os
size_300 = (300, 300)
for f in os.listdir('.'):
if f.endswith('.jpg'):
i = Image.open(f)
fn, fext = os.path.splitext(f)
i.thumbnail(size_300)
i.save('300/{}_300{}.png'.format(fn, fext))
---------------------------------
---------------------------------
==========================================
from PIL import Image
import os
size_300 = (300, 300)
size_700 = (700, 700)
for f in os.listdir('.'):
if f.endswith('.jpg'):
i = Image.open(f)
fn, fext = os.path.splitext(f)
i.thumbnail(size_700)
i.save('700/{}_700{}.png'.format(fn, fext))
i.thumbnail(size_300)
i.save('300/{}_300{}.png'.format(fn, fext))
---------------------------------
---------------------------------
==========================================
from PIL import Image
import os
image1 = Image.open('apple1.jpg')
image1.rotate(90).save('apple1_mod.jpg')
---------------------------------
---------------------------------
==========================================
from PIL import Image
import os
image1 = Image.open('apple1.jpg')
image1.convert(mode='L').save('apple1_mod.jpg')
---------------------------------
---------------------------------
==========================================
from PIL import Image, ImageFilter
import os
image1 = Image.open('apple1.jpg')
image1.filter(ImageFilter.GaussianBlur()).save('apple1_mod.jpg')
---------------------------------
---------------------------------
==========================================
from PIL import Image, ImageFilter
import os
image1 = Image.open('apple1.jpg')
image1.filter(ImageFilter.GaussianBlur(15)).save('apple1_mod.jpg')
---------------------------------
---------------------------------