प्रेजेंटेशन में इमेजेज के साथ काम करना — Aspose.Slides FOSS for Python
Aspose.Slides FOSS for Python lets you embed images in a presentation’s shared image collection and display them on slides using PictureFrame आकार। इमेज को आकार की background fills के रूप में भी उपयोग किया जा सकता है द्वारा FillType.PICTURE.
फ़ाइल से छवि जोड़ना
डिस्क से image bytes लोड करें और उन्हें प्रस्तुति की image collection में जोड़ें के साथ prs.images.add_image(). फिर इमेज को स्लाइड पर एक के रूप में रखें PictureFrame:
import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
# Add the image to the shared collection
with open("logo.png", "rb") as f:
img = prs.images.add_image(f.read())
# Place it on the slide as a PictureFrame
slide = prs.slides[0]
slide.shapes.add_picture_frame(ShapeType.RECTANGLE, 50, 50, 300, 200, img)
prs.save("with-image.pptx", SaveFormat.PPTX)चार positional arguments to add_picture_frame() हैं: x, y, width, height पॉइंट्स में।.
बाइट्स से इमेज जोड़ना
यदि आपके पास पहले से ही image bytes हैं (उदाहरण के लिए, URL से डाउनलोड किए गए या डेटाबेस से पढ़े गए), तो उन्हें सीधे पास करें to add_image():
import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType
from aspose.slides_foss.export import SaveFormat
# Simulate having bytes in memory
with open("photo.jpg", "rb") as f:
image_bytes = f.read()
with slides.Presentation() as prs:
img = prs.images.add_image(image_bytes)
prs.slides[0].shapes.add_picture_frame(ShapeType.RECTANGLE, 100, 80, 400, 250, img)
prs.save("from-bytes.pptx", SaveFormat.PPTX)PictureFrame की स्थिति निर्धारण और आकार निर्धारण
यह PictureFrame द्वारा लौटाया गया add_picture_frame() सभी को विरासत में लेता है Shape ज्यामिति गुणधर्म और निर्माण के बाद पुनः स्थित किया जा सकता है:
import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
with open("photo.jpg", "rb") as f:
img = prs.images.add_image(f.read())
pf = prs.slides[0].shapes.add_picture_frame(ShapeType.RECTANGLE, 0, 0, 100, 100, img)
# Reposition and resize after creation
pf.x = 50
pf.y = 100
pf.width = 350
pf.height = 250
prs.save("positioned.pptx", SaveFormat.PPTX)छवि को शैप फ़िल के रूप में उपयोग करना
कोई भी shape (सिर्फ PictureFrame नहीं) इमेज को अपनी background fill के रूप में उपयोग कर सकता है। सेट fill_type = FillType.PICTURE और इमेज को असाइन करें to picture_fill_format.picture.image:
import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType, FillType, PictureFillMode
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
with open("background.png", "rb") as f:
img = prs.images.add_image(f.read())
slide = prs.slides[0]
shape = slide.shapes.add_auto_shape(ShapeType.ROUND_CORNER_RECTANGLE, 50, 50, 400, 250)
shape.fill_format.fill_type = FillType.PICTURE
shape.fill_format.picture_fill_format.picture_fill_mode = PictureFillMode.STRETCH
shape.fill_format.picture_fill_format.picture.image = img
prs.save("picture-fill.pptx", SaveFormat.PPTX)PictureFillMode.STRETCH इमेज को पूरे shape में भरने के लिए स्केल करता है। उपयोग करें TILE एक दोहराव वाले टाइल पैटर्न के लिए।.
स्लाइड्स में कई इमेजेज जोड़ना
में जोड़ी गई इमेजेज prs.images सभी स्लाइड्स में साझा किए जाते हैं। वही Image object को कई स्लाइड्स पर डेटा को दोहराए बिना उपयोग किया जा सकता है:
import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
with open("logo.png", "rb") as f:
logo = prs.images.add_image(f.read())
# Add the same image to both slides
prs.slides[0].shapes.add_picture_frame(ShapeType.RECTANGLE, 600, 10, 100, 40, logo)
prs.save("shared-image.pptx", SaveFormat.PPTX)