Python에서 PPT를 JPG로 변환

Python 응용 프로그램에서 PowerPoint 프레젠테이션으로 작업하는 동안 PPT에 대한 축소판을 생성해야 할 수 있습니다. 예를 들어, 슬라이드쇼나 프레젠테이션 조작 도구를 만드는 동안. 이 기사에서는 Python에서 PPT를 JPG 이미지로 변환하여 축소판을 생성하는 방법을 배웁니다. 또한 사용자 정의 치수가 있는 JPG 이미지를 생성하고 슬라이드 노트 및 주석을 렌더링하는 방법도 다룰 것입니다.

JPG 변환기에 파이썬 PPT

PowerPoint 프레젠테이션을 JPG 이미지로 변환하려면 .NET을 통한 Python용 Aspose.Slides를 사용합니다. Python에서 프레젠테이션 조작 기능을 구현하는 강력한 라이브러리입니다. 라이브러리를 사용하여 프레젠테이션을 원활하게 생성, 수정 및 변환할 수 있습니다. 다음 pip 명령을 사용하여 PyPI에서 라이브러리를 설치합니다.

> pip install aspose.slides

Python에서 PPT를 JPG로 변환

다음은 Python에서 PPT 프레젠테이션을 JPG 이미지로 변환하는 단계입니다.

  • 먼저 Presentation 클래스를 사용하여 프레젠테이션 파일을 로드합니다.
  • 그런 다음 Pesentation.slides 컬렉션을 사용하여 슬라이드를 반복합니다.
    • 슬라이드의 인덱스를 사용하여 컬렉션의 각 ISlide에 대한 참조를 가져옵니다.
    • 마지막으로 ISlide.get_thumbnail().save(string, ImageFormat.jpeg) 메서드를 사용하여 슬라이드를 JPG 이미지로 변환합니다.

다음 코드 샘플은 Python에서 PowerPoint PPTX를 JPG로 변환하는 방법을 보여줍니다.

import aspose.slides as slides
import aspose.pydrawing as drawing

# Load presentation
pres = slides.Presentation("presentation.pptx")

# Loop through slides
for index in range(pres.slides.length):
    # Get reference of slide
    slide = pres.slides[index]

    # Save as JPG
    slide.get_thumbnail().save("slide_{i}.jpg".format(i = index), drawing.imaging.ImageFormat.jpeg)

다음 스크린샷은 프레젠테이션의 첫 번째 슬라이드의 결과 JPG 이미지를 보여줍니다.

Python에서 PowerPoint PPT를 JPG로 변환

결과 JPG 이미지

PPT에서 JPG로 - 이미지 크기 사용자 정의

너비와 높이를 제공하여 결과 JPG 이미지의 크기를 사용자 정의할 수도 있습니다. 또한 요구 사항에 따라 이미지의 크기를 조정할 수 있습니다. 다음 단계는 사용자 정의 치수 및 배율을 사용하여 PPT를 JPG로 변환하는 방법을 보여줍니다.

  • 먼저 Presentation 클래스를 사용하여 프레젠테이션 파일을 로드합니다.
  • JPG 이미지의 너비와 높이를 설정하는 두 개의 변수를 만듭니다.
  • 지정된 너비와 높이를 사용하여 이미지의 X 및 Y 배율을 설정합니다.
  • Pesentation.slides 컬렉션을 사용하여 슬라이드를 반복합니다.
    • 슬라이드의 인덱스를 사용하여 컬렉션에서 각 ISlide의 참조를 가져옵니다.
    • ISlide.get_thumbnail(scaleX, scaleY).save(string, ImageFormat.jpeg) 메서드를 사용하여 슬라이드를 JPG로 변환합니다.

다음 코드 샘플은 Python에서 사용자 지정 크기 조정 및 치수를 사용하여 PPT 축소판을 생성하는 방법을 보여줍니다.

import aspose.slides as slides
import aspose.pydrawing as drawing

# Load presentation
pres = slides.Presentation("presentation.pptx")

desiredX = 1200
desiredY = 800
scaleX = (float)(1.0 / pres.slide_size.size.width) * desiredX
scaleY = (float)(1.0 / pres.slide_size.size.height) * desiredY

# Loop through slides
for index in range(pres.slides.length):
    # Get reference of slide
    slide = pres.slides[index]

    # Save as JPG
    slide.get_thumbnail(scaleX, scaleY).save("slide_{i}.jpg".format(i = index), drawing.imaging.ImageFormat.jpeg)

메모 및 주석 포함 - Python PPT에서 JPG로

MS PowerPoint에서는 프레젠테이션의 각 슬라이드에 대한 설명과 메모를 작성할 수도 있습니다. 기본적으로 주석과 메모는 PPT에서 JPG로 변환할 때 렌더링되지 않습니다. 그러나 아래 단계에 따라 결과 JPG 이미지에 포함할 수 있습니다.

  • 먼저 Presentation 클래스를 사용하여 프레젠테이션 파일을 로드합니다.

  • 결과 이미지의 너비와 높이를 지정하여 Bitmap 개체를 만듭니다.

  • RenderingOptions 클래스의 객체를 생성합니다.

  • RenderingOptions.notes\comments\layouting.notes\position 속성을 사용하여 메모의 위치를 지정합니다.

  • 주석을 포함하려면 RenderingOptions.notes\comments\layouting.comments\position 속성을 사용하십시오.

  • Pesentation.slides 컬렉션의 슬라이드를 반복합니다.

    • Graphics.from\image(Bitmap) 메서드를 사용하여 Bitmap에서 그래픽 객체를 생성합니다.

    • Presentation.slides[index].render\to\graphics(RenderingOptions, graphics) 메서드를 사용하여 슬라이드를 그래픽으로 렌더링합니다.

    • Bitmap.save(string, ImageFormat.jpeg) 메서드를 사용하여 슬라이드를 JPG로 저장합니다.

다음 코드 샘플은 PPT에서 JPG로 변환하는 메모와 주석을 렌더링하는 방법을 보여줍니다.

import aspose.slides as slides
import aspose.pydrawing as drawing

# Load presentation
pres = slides.Presentation("presentation.pptx")

# Create a bitmap object
bmp = drawing.Bitmap(1000, 700)

# Set notes and comments position
opts = slides.export.RenderingOptions()
opts.notes_comments_layouting.notes_position = slides.export.NotesPositions.BOTTOM_TRUNCATED

# To include comments
opts.notes_comments_layouting.comments_area_color = drawing.Color.orange
opts.notes_comments_layouting.comments_area_width = 200
opts.notes_comments_layouting.comments_position = slides.export.CommentsPositions.RIGHT

# Loop through slides
for index in range(pres.slides.length):
    # Generate graphics from bitmap
    graphics = drawing.Graphics.from_image(bmp)

    # Render slide to graphics
    pres.slides[index].render_to_graphics(opts, graphics)

    # Save as JPG
    bmp.save("slide_{i}.jpg".format(i = index), drawing.imaging.ImageFormat.jpeg)

다음 스크린샷은 슬라이드 노트와 주석이 포함된 결과 JPG 이미지를 보여줍니다.

Python에서 주석 및 메모가 포함된 PPT를 JPG로 변환

슬라이드 노트 및 주석이 포함된 PPT를 JPG로

무료 라이선스 받기

임시 라이선스를 얻으면 평가 제한 없이 .NET을 통해 Python용 Aspose.Slides를 사용할 수 있습니다.

결론

이 기사에서는 Python에서 PowerPoint PPT 또는 PPTX를 JPG 이미지로 변환하는 방법을 배웠습니다. 또한 사용자 정의 치수 및 배율을 사용하여 JPG 이미지를 생성하는 방법을 살펴보았습니다. 또한 PPT에서 JPG로 변환할 때 슬라이드 노트와 주석을 포함하는 방법도 다루었습니다. .NET을 통한 Python용 Aspose.Slides는 문서를 사용하여 탐색할 수 있는 다양한 기능도 제공합니다. 질문이 있는 경우 포럼에 문의하십시오.

또한보십시오

팁: Aspose FREE PowerPoint to JPG 변환기를 확인하는 것이 좋습니다.