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 will be replaced by their Modern API equivalents. Methods that use aspose.pydrawing.Graphics
are deprecated, and support for them will be removed from the public API.
Removal of the deprecated API that depends on aspose.pydrawing
is planned for release 24.8.
Modern API
The following classes and enums have been added to the public API:
aspose.slides.IImage
— represents a raster or vector image.aspose.slides.ImageFormat
— represents an image file format.aspose.slides.Images
— provides methods to create and work withIImage
.
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
interface mirrors the separate APIs of the Image
and 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) | 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 that use aspose.pydrawing.Graphics
are deprecated; support for them will be removed from the public API.
The API members that rely on aspose.pydrawing.Graphics
and will be removed include:
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)