PIL 이미지 기본적 사용법
img = Image.open('test_file.jpg')
img.show()
from PIL import Image
with Image.open("test_file.jpg") as im:
im.show()
img.width, img.height, img.size
image.resize((w, h))
Thumbnail 파일 생성하기
from PIL import Image
import glob, os
size = 128, 128
for infile in glob.glob("*.jpg"):
file, ext = os.path.splitext(infile)
im = Image.open(infile)
im.thumbnail(size)
im.save(file + ".thumbnail", "JPEG")
img = Image.open('test_file.thumbnail')
img.show()
이미지 겹치기(사이즈가 같아야함)
Image.alpha_composite(img_1, img_2)
Image.blend(img_1, img_2, .1)
이미지 증식
Image.crop(box=None)
image.paste(im, box=None, mask=None)
image.rorate(angle, resample=0, expand=0, center=None, translate=None)
image.transpose(Image.FL)
image.transpose(Image.FLIP_TOP_BOTTOM)
image.transpose(Image.ROTATE_90)
image.transform(size, method, data=None, resample=0, fill=1, fillcolor=None)
from PIL import Image, ImageDraw, ImageFont, ImageFilter
img = Image.open('cat_img.jpg').resize((300,300))
d = ImageDraw.Draw(img)
d.text((40, 10), 'this is BLUR', fill="Red")
img = img.filter(ImageFilter.BLUR)
img.save('BLUR.jpg','jpeg')
img.show()
ImageFilter | 사진 |
---|
BLUR |  |
CONTOUR |  |
DETAIL |  |
EDGE_ENHANCE |  |
EMBOSS |  |
FIND_EDGES |  |
SHARPEN |  |
SMOOTH |  |
이미지 편집 시 필요한 함수들
from PIL import Image
im = Image.open("hopper.jpg")
print(im.getbands())
im = Image.open("hopper.jpg")
print(im.getbbox())
Image.getchannel(channel)
이미지에 텍스트 삽입
from PIL import Image, ImageDraw, ImageFont
im = Image.open('cat_img.jpg').resize((150,150))
ft = ImageFont.truetype('Pantherdam Signature Italic.ttf', size=20)
d = ImageDraw.Draw(im)
d.text((10, 10), 'text any text', font=ft, fill="#ff3")
im.show()