-- 선언부 --
import Image
global ext
ext = ".jpg"
imageFile = "test.jpeg"
im1 = Image.open(imageFile)
-- 이미지 조작 --
Resize
def imgResize(im): div = 2 width = im.size[0] / div height = im.size[1] / div im2 = im.resize((width, height), Image.NEAREST) # use nearest neighbour im3 = im.resize((width, height), Image.BILINEAR) # linear interpolation in a 2x2 environment im4 = im.resize((width, height), Image.BICUBIC) # cubic spline interpolation in a 4x4 environment im5 = im.resize((width, height), Image.ANTIALIAS) # best down-sizing filter im2.save("NEAREST" + ext) im3.save("BILINEAR" + ext) im4.save("BICUBIC" + ext) im5.save("ANTIALIAS" + ext) imgResize(im1)
Crop
def imgCrop(im): box = (50, 50, 200, 300) region = im.crop(box) region.save("CROPPED" + ext) imgCrop(im1)
Transpose
def imgTranspose(im): box = (50, 50, 200, 300) region = im.crop(box) region = region.transpose(Image.ROTATE_180) im.paste(region, box) im.save("TRANSPOSE" + ext) imgTranspose(im1)
Band merge
def bandMerge(im): r, g, b = im.split() im = Image.merge("RGB", (g,g,g)) im.save("MERGE" + ext) bandMerge(im1)
Blur
import ImageFilter def filterBlur(im): im1 = im.filter(ImageFilter.BLUR) im1.save("BLUR" + ext) filterBlur(im1)
Find contours
def filterContour(im): im1 = im.filter(ImageFilter.CONTOUR) im1.save("CONTOUR" + ext) filterContour(im1)
Find edges
def filterFindEdges(im): im1 = im.filter(ImageFilter.FIND_EDGES) im1.save("EDGES" + ext) filterFindEdges(im1)
-- 이미지 만들어서 글자 쓰기 --
image = Image.new("RGBA", (600,150), (255,255,255))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("resources/HelveticaNeueLight.ttf", fontsize)
draw.text((10, 0), txt, (0,0,0), font=font)
img_resized = image.resize((188,45), Image.ANTIALIAS)
http://en.wikibooks.org/wiki/Python_Imaging_Library/Editing_Pixels
'리눅스 서버에 대해서 > python' 카테고리의 다른 글
파이선으로 만든 간단한 captcha (0) | 2013.09.20 |
---|---|
파이선 간단한 captchr 소스 (0) | 2013.09.20 |
파이썬의 PIL 이미지 라이브러리 사용 강좌 (0) | 2013.09.18 |
captcha 우회하기 (0) | 2013.09.18 |
CAPTCHA 만들기 (0) | 2013.05.15 |