python-pptx
를 사용하여 jpg를 pptx파일로 만든다.
아래 코드를 요약하면 #00001.jpg
부터 #00067.jpg
까지 jpg폴더 안에 있고 convert.pptx
로 묶는다.
from pptx import Presentation
from pptx.util import Inches
_width = Inches(11.7) # A4 가로 사이즈
_height = Inches(8.3) # A4 세로 사이즈
prs = Presentation()
prs.slide_width = _width
prs.slide_height = _height # 슬라이드 크기 지정
blank_slide_layout = prs.slide_layouts[6] # 빈 슬라이드 레이아웃
left = top = Inches(0) # 왼쪽, 위 마진
for item in range(1, 68, 1):
if (item < 10):
img_path = './jpg/#0000'+str(item)+'.jpg'
else:
img_path = './jpg/#000'+str(item)+'.jpg'
slide = prs.slides.add_slide(blank_slide_layout) # 새 슬라이드 추가
pic = slide.shapes.add_picture(img_path, left, top, _width, _height) # 새 사진 추가
prs.save('convert.pptx')