Enhance Image Processing with the Modern API

Introduction

The Aspose.Slides for Python public API currently depends on the following aspose.pydrawing types:

  • aspose.pydrawing.Graphics
  • aspose.pydrawing.Image
  • aspose.pydrawing.Bitmap
  • aspose.pydrawing.printing.PrinterSettings

As of version 24.4, this public API is deprecated due to changes in the Aspose.Slides for Python public API.

To eliminate aspose.pydrawing from the public API, we introduced the Modern API. Methods that use aspose.pydrawing.Image and aspose.pydrawing.Bitmap are deprecated and should be replaced by their Modern API equivalents. Methods that use aspose.pydrawing.Graphics are deprecated and have no direct Modern API replacement.

In current versions, treat the public API that depends on aspose.pydrawing as legacy/deprecated. Use the Modern API for new code and when migrating existing image-processing workflows.

Modern API

The following classes and enums have been added to the public API:

Use get_image to render a single slide or shape. Use get_images to render several presentation slides. Use Images methods to load images, add_image with IImage to add them to a presentation, and replace_image with IImage to update an existing presentation image.

A typical usage scenario for the new API looks like this:

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

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    with slides.Images.from_file("image.png") as image:
        pp_image = presentation.images.add_image(image)

    slide.shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 10, 10, 100, 100, pp_image)

    with slide.get_image(drawing.Size(1920, 1080)) as slide_image:
        slide_image.save("slide1.jpeg", slides.ImageFormat.JPEG)

Replace Old Code with the Modern API

For an easier transition, the new IImage class mirrors the separate APIs of the aspose.pydrawing.Image and aspose.pydrawing.Bitmap classes. In most cases, you only need to replace calls to methods that use aspose.pydrawing with their Modern API equivalents.

Get a Slide Thumbnail

Deprecated API:

import aspose.slides as slides

with slides.Presentation("sample.pptx") as presentation:
    slide = presentation.slides[0]

    slide.get_thumbnail().save("slide1.png")

Modern API:

import aspose.slides as slides

with slides.Presentation("sample.pptx") as presentation:
    slide = presentation.slides[0]

    with slide.get_image() as image:
        image.save("slide1.png")

Get a Shape Thumbnail

Deprecated API:

import aspose.slides as slides

with slides.Presentation("sample.pptx") as presentation:
    shape = presentation.slides[0].shapes[0]
    
    shape.get_thumbnail().save("shape.png")

Modern API:

import aspose.slides as slides

with slides.Presentation("sample.pptx") as presentation:
    shape = presentation.slides[0].shapes[0]

    with shape.get_image() as image:
        image.save("shape.png")

Get a Presentation Thumbnail

Deprecated API:

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

with slides.Presentation("sample.pptx") as presentation:
    thumbnails = presentation.get_thumbnails(slides.export.RenderingOptions(), drawing.Size(1980, 1028))

    for index, thumbnail in enumerate(thumbnails):
        thumbnail.save(f"slide_{index}.png", drawing.imaging.ImageFormat.png)

Modern API:

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

with slides.Presentation("sample.pptx") as presentation:
    thumbnails = presentation.get_images(slides.export.RenderingOptions(), drawing.Size(1980, 1028))

    for index, thumbnail in enumerate(thumbnails):
        thumbnail.save(f"slide_{index}.png", slides.ImageFormat.PNG)

Add a Picture to a Presentation

Deprecated API:

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

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    image = drawing.Image.from_file("image.png")
    pp_image = presentation.images.add_image(image)
    slide.shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 10, 10, 100, 100, pp_image)

Modern API:

import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    with slides.Images.from_file("image.png") as image:
        pp_image = presentation.images.add_image(image)

    slide.shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 10, 10, 100, 100, pp_image)

Methods and Properties to Be Removed and Their Modern Replacements

Presentation Class

Method Signature Replacement Method Signature
get_thumbnails(options) get_images(options)
get_thumbnails(options, slides) get_images(options, slides)
get_thumbnails(options, scale_x, scale_y) get_images(options, scale_x, scale_y)
get_thumbnails(options, slides, scale_x, scale_y) get_images(options, slides, scale_x, scale_y)
get_thumbnails(options, image_size) get_images(options, image_size)
get_thumbnails(options, slides, image_size) get_images(options, slides, image_size)
save(fname, format, response, show_inline) No Modern API replacement
save(fname, format, options, response, show_inline) No Modern API replacement
print() No Modern API replacement
print(printer_settings) No Modern API replacement
print(printer_name) No Modern API replacement
print(printer_settings, pres_name) No Modern API replacement

Slide Class

Method Signature Replacement Method Signature
get_thumbnail() get_image()
get_thumbnail(scale_x, scale_y) get_image(scale_x, scale_y)
get_thumbnail(image_size) get_image(image_size)
get_thumbnail(options) get_image(options: ITiffOptions)
get_thumbnail(options) get_image(options: IRenderingOptions)
get_thumbnail(options, scale_x, scale_y) get_image(options, scale_x, scale_y)
get_thumbnail(options, image_size) get_image(options, image_size)
render_to_graphics(options, graphics) No Modern API replacement
render_to_graphics(options, graphics, scale_x, scale_y) No Modern API replacement
render_to_graphics(options, graphics, rendering_size) No Modern API replacement

Shape Class

Method Signature Replacement Method Signature
get_thumbnail() get_image()
get_thumbnail(bounds, scale_x, scale_y) get_image(bounds, scale_x, scale_y)

ImageCollection Class

Method Signature Replacement Method Signature
add_image(image: aspose.pydrawing.Image) add_image(image)

PPImage Class

Method/Property Signature Replacement Method/Property Signature
replace_image(new_image: aspose.pydrawing.Image) replace_image(new_image)
system_image image

ImageWrapperFactory Class

Method Signature Replacement Method Signature
create_image_wrapper(image: aspose.pydrawing.Image) create_image_wrapper(image)

PatternFormat Class

Method Signature Replacement Method Signature
get_tile_image(background, foreground) get_tile(background, foreground)
get_tile_image(style_color) get_tile(style_color)

IPatternFormatEffectiveData Class

Method Signature Replacement Method Signature
get_tile_image(background, foreground) get_tile_i_image(background, foreground)

Output Class

Method Signature Replacement Method Signature
add(path, image: aspose.pydrawing.Image) add(path, image)

API Support for aspose.pydrawing.Graphics

Methods that use aspose.pydrawing.Graphics are deprecated and have no direct Modern API replacement.

Use the Modern API image-rendering methods instead of the API that renders to aspose.pydrawing.Graphics:

  • aspose.pydrawing.Slide.render_to_graphics(options, graphics)
  • aspose.pydrawing.Slide.render_to_graphics(options, graphics, scale_x, scale_y)
  • aspose.pydrawing.Slide.render_to_graphics(options, graphics, rendering_size)

FAQ

Why was aspose.pydrawing.Graphics dropped?

Support for aspose.pydrawing.Graphics is deprecated in the public API to unify work with rendering and images, eliminate ties to platform-specific dependencies, and switch to a cross-platform approach with IImage. Use get_image or get_images instead of rendering to aspose.pydrawing.Graphics.

What is the practical benefit of IImage compared to aspose.pydrawing.Image/aspose.pydrawing.Bitmap?

IImage unifies working with both raster and vector images, simplifies saving to various formats via ImageFormat, reduces dependence on pydrawing, and makes code more portable across environments.

Will the Modern API affect the performance of generating thumbnails?

Switching from get_thumbnail to get_image does not worsen scenarios: the new methods provide the same capabilities for producing images with options and sizes, while retaining support for rendering options. The specific gain or drop depends on the scenario, but functionally the replacements are equivalent.