Modern API

Introduction

Currently, the Aspose.Slides for Python via .NET library has dependencies in its public API on the following classes from aspose.pydrawing:

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

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

In order to get rid of dependencies on aspose.pydrawing in the public API, we added the so-called “Modern API”. Methods with aspose.pydrawing.Image and aspose.pydrawing.Bitmap are declared deprecated and will be replaced with the corresponding methods from the Modern API. Methods with aspose.pydrawing.Graphics are declared deprecated and their support will be removed from the public API.

Removal of the deprecated public API with dependencies on aspose.pydrawing will be in release 24.8.

Modern API

Added the following classes and enums to the public API:

A typical scenario of using the new API may look as follows:

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

with slides.Presentation() as pres:
    image = slides.Images.from_file("image.png")
    pp_image = pres.images.add_image(image)
    pres.slides[0].shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 10.0, 10.0, 100.0, 100.0, pp_image)
    slide_image = pres.slides[0].get_image(drawing.Size(1920, 1080))
    slide_image.save("slide1.jpeg", slides.ImageFormat.JPEG)

Replacing old code with Modern API

For ease of transition, the interface of the new IImage repeats the separate signatures of the Image and Bitmap classes. In general, you will just need to replace the call to the old method using aspose.pydrawing with the new one.

Getting a slide thumbnail

Code using a deprecated API:

import aspose.slides as slides

with slides.Presentation("pres.pptx") as pres:
    pres.slides[0].get_thumbnail().save("slide1.png")

Modern API:

import aspose.slides as slides

with slides.Presentation("pres.pptx") as pres:
    pres.slides[0].get_image().save("slide1.png")

Getting a shape thumbnail

Code using a deprecated API:

import aspose.slides as slides

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

Modern API:

import aspose.slides as slides

with slides.Presentation("pres.pptx") as pres:
    pres.slides[0].shapes[0].get_image().save("shape.png")

Getting a presentation thumbnail

Code using a deprecated API:

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

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

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

Modern API:

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

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

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

Adding a picture to a presentation

Code using a deprecated API:

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

with slides.Presentation() as pres:
    image = drawing.Image.from_file("image.png")
    pp_image = pres.images.add_image(image)
    pres.slides[0].shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 10.0, 10.0, 100.0, 100.0, pp_image)

Modern API:

import aspose.slides as slides

with slides.Presentation() as pres:
    image = slides.Images.from_file("image.png")
    pp_image = pres.images.add_image(image)
    pres.slides[0].shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 10.0, 10.0, 100.0, 100.0, pp_image)

Methods/properties to be removed and their replacement in Modern API

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) Will be deleted completely
save(fname, format, options, response, show_inline) Will be deleted completely
print() Will be deleted completely
print(printer_settings) Will be deleted completely
print(printer_name) Will be deleted completely
print(printer_settings, pres_name) Will be deleted completely

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: ITiffOotions)
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) Will be deleted completely
render_to_graphics(options, graphics, scale_x, scale_y) Will be deleted completely
render_to_graphics(options, graphics, rendering_size) Will be deleted completely

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 will be discontinued

Methods with aspose.pydrawing.Graphics are declared deprecated and their support will be removed from the public API.

The part of the API that uses it will be removed:

  • 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)