Please specify what version of the library you are using......: [3.11.0] (issue still exists in 3.12.0)
Please specify what version(s) of PowerPoint you are targeting: [diverse]
Please specify what web browser you are using.................: [Google Chrome 116.0.5845.96 / node 20.0.0]
Desired Behavior
Placing an image with one dimension above 100px and one dimension below 100px should calculate aspect ratio correctly.
The output srcRect of the code example below should be
<a:srcRect l="0" r="0" t="-20047" b="-20047"/>
Observed Behavior
Aspect ratio is calculated wrong, because it interprets the dimension below 100px as inches and the one above 100px as EMU.
The output srcRect of the code example below is
I'd recommend to either allow adding other units when adding w/h values as String, OR don't handle w/h values separately, usually they should use the same unit, OR don't bother converting these values to EMU at all, because they are only used for an aspect-ratio calculation, so the result stays the same, no matter if its inches or emu or something else (but %).
Steps to Reproduce
import pptxgen from "pptxgenjs";
let pres = new pptxgen();
let slide = pres.addSlide();
slide.addImage({
"x": "19%",
"y": "54%",
// the next two lines are the important part. this is the image size in pixels
"w": 2899,
"h": 97,
"path": "<PATH_TO_IMAGE>",
"sizing": {
"type": "contain",
"w": "36%",
"h": "3%",
}
});
pres.writeFile({ fileName: "Test.pptx" });
Workaround
As a workaround I'm currently checking if one of the dimensions is below 100 and if so, I multiply both dimensions by a value that lets it be over 100. This is working because those dimensions are only used for aspect ratio calculation and the result of that calculation is not changed by such a scale.
Issue Category
Product Versions
Desired Behavior
Placing an image with one dimension above 100px and one dimension below 100px should calculate aspect ratio correctly.
The output srcRect of the code example below should be
Observed Behavior
Aspect ratio is calculated wrong, because it interprets the dimension below 100px as inches and the one above 100px as EMU. The output srcRect of the code example below is
The generated pptx File can't even be opened by PowerPoint without a warning that the file is damaged.
It is caused by this Line of code:
https://github.com/gitbrent/PptxGenJS/blob/035cf6b26239e2ea1f27eefbcdb8134e504eb4f4/src/gen-utils.ts#L25
When adding a breakpoint here:
https://github.com/gitbrent/PptxGenJS/blob/035cf6b26239e2ea1f27eefbcdb8134e504eb4f4/src/gen-xml.ts#L65
the code example below shows the following value for
imgSize
:I'd recommend to either allow adding other units when adding w/h values as String, OR don't handle w/h values separately, usually they should use the same unit, OR don't bother converting these values to EMU at all, because they are only used for an aspect-ratio calculation, so the result stays the same, no matter if its inches or emu or something else (but %).
Steps to Reproduce
Workaround
As a workaround I'm currently checking if one of the dimensions is below 100 and if so, I multiply both dimensions by a value that lets it be over 100. This is working because those dimensions are only used for aspect ratio calculation and the result of that calculation is not changed by such a scale.