Insert an Image Inside a Presentation Shape Using Aspose.Slides for Node.js

Hi team, is there a way I can insert an image directly inside of any shape already present in the slide without using slide.getShapes().addPictureFrame() method ? Like shape.addPictureFrame() or without need of passing X-Y coordinaates. For example we do with setText and setChartData.

@karanmarsh,
Thank you for posting the question.

In PowerPoint presentations, you can fill shapes with images. The following code example shows you how to do this using Aspose.Slides for Node.js:

presentation = new aspose.slides.Presentation("sample.pptx");

imageStream = java.newInstanceSync("java.io.FileInputStream", "image.png");
image = presentation.getImages().addImage(imageStream);

firstShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);

firstShape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Picture));
firstShape.getFillFormat().getPictureFillFormat().setPictureFillMode(aspose.slides.PictureFillMode.Tile);
firstShape.getFillFormat().getPictureFillFormat().getPicture().setImage(image);

presentation.save("output.pptx", aspose.slides.SaveFormat.Pptx);
presentation.dispose();

This works. Thanks. In order to place the image with exact size of the shape I should setPictureFillMode to Stretch, right ?

@karanmarsh,
Yes, you are right but please note if the proportions of the shape do not correspond to the proportions of the image, the image inside the shape will be distorted.