1 답변
-
썸네일이라면 크기를 줄이는거 겠네요.
최대 크기를 정해놓고
ratio = min(maxwidth/width, maxheight/height)
로 비율(ratio)을 구하면 됩니다.
아니면 PIL에서 제공하는 Image.thumbnail(size, resample=3)를 써도 되겠네요.
(
size
이하로 썸네일을 만들어 줍니다.)튜토리얼에서 예제를 갖고 왔으니 참고하세요
import os, sys import Image size = 128, 128 for infile in sys.argv[1:]: outfile = os.path.splitext(infile)[0] + ".thumbnail" if infile != outfile: try: im = Image.open(infile) im.thumbnail(size, Image.ANTIALIAS) im.save(outfile, "JPEG") except IOError: print "cannot create thumbnail for '%s'" % infile
댓글 입력