PptxGenJS icon indicating copy to clipboard operation
PptxGenJS copied to clipboard

image placed in placeholder loses aspect ratio

Open ccassan opened this issue 3 years ago • 3 comments

Hi, I am using pptxgenjs version 3.7.1. I created a slide master with a placeholder of type "pic", with width=height=2. When I insert an image with a different aspect ratio in this placeholder, its aspect ratio is not maintained, regardless of what I provide in the sizing property. I would like my image to be contained in the placeholder, while maintaining its aspect ratio.

with ph : PlaceholderProps sourceW = image.width sourceH = image.height

slide.addImage({data:image.src, x: ph.x, y:ph.y, w: sourceW, h: sourceH, sizing: { type: "contain", w: ph.w as number, h: ph.h as number }});
--> OK slide.addImage({data:image.src, placeholder: placeholder, w: sourceW, h: sourceH, sizing: { type: "contain", w: ph.w as number, h: ph.h as number }}); --> KO

Is this feature supported in 3.7.1? And if so, what properties should I send to addImage to get the expected result?

Ideally I would like to provide the placeholder name without knowing its size and position, and just provide the sizing type.

slide.addImage({data:image.src, placeholder: placeholder, w: sourceW, h: sourceH, sizing: { type: "contain"});

Thanks Cl.

ccassan avatar Sep 02 '21 16:09 ccassan

@ccassan - so when you use the same values for w and h in the two examples above, you're saying the image has 2 different aspect ratios once generated?

gitbrent avatar Oct 01 '21 03:10 gitbrent

@gitbrent , yes, the only difference in the two calls is the placeholder.

clairecassan avatar Oct 01 '21 06:10 clairecassan

It works now in 3.12.0, the ratio is maintained

slide.addImage({ data:image.src, placeholder: placeholder, w: sourceW, h: sourceH, sizing: { type: "contain", w: ph.w as number, h: ph.h as number } });

clairecassan avatar May 25 '23 06:05 clairecassan