랭귀지/python
Python 파일을 JPEG으로 변환하기
유키공
2018. 6. 3. 21:39
파일을 JPEG으로 변환하기
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)
im.save(outfile, "JPEG")
except IOError:
print "cannot create thumbnail for", infile
splitext(p)
pathname에서 확장자를 분리합니다.
확장자는 점(.) 뒤에 있는 텍스트 입니다. "(root, ext)"를 반환하고, ext는 비어 있을 수도 있습니다.
두 번째 인자는 파일 포맷을 명시적으로 지정할 수 있는 save 메소드에 사용될 수 있습니다. 만약 비표준 확장자를 사용한다면, 이와 같이 파일 포맷을 지정해야만 합니다.