using pptxgenjs, add an image that takes the full size of the slide

3k views Asked by At

PptxGenJS allows creating a Powerpoint file by scripting. https://gitbrent.github.io/PptxGenJS/

we can add an image as follows:

slide.addImage({ path: "images/chart_world_peace_near.png", x:..., y:..., w:..., h:...});

I need to resize the image to the full size of the slide, with the aspect ratio. So, I need to know the size of the image and the size of the slide, as follows:

scaled_image_width = slide_width
scaled_image_height = image_height * scaled_image_width / image_width;
if (scaled_image_height > slide_height) {
  scaled_image_height = slide_height
  scaled_image_width = image_width * scaled_image_height / image_height;
}

However, I don't see a way in PptxGenJS to get the size of the image and the size of the slide. How can I achieve this?

2

There are 2 answers

0
Manoj Kandimalla On

You can add background to slide using below

var pptx1 = new PptxGenJS();
var slide = pptx1.addSlide();

After adding slide you can add background to it

slide.background = {path:"Image URL"};
0
Creativos Online App On

you can use string format for width, for example: w: '100%', this will asign slide width to image.