Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions acorn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
150 changes: 150 additions & 0 deletions add_image_with_rounding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@

import pptxgen from "pptxgenjs";

const pptx = new pptxgen();

const slide = pptx.addSlide();


slide.addImage({
path: "https://files.chroniclehq.com/card-background-v2/thumbnail/v2-gradient-01-light.jpg",
x: 0.528,
y: 1.051,
w: 2.479,
h: 1.76,
rounding: true,
rectRadius: 0.2
});

slide.addImage({
path: "https://files.chroniclehq.com/card-background-v2/thumbnail/v2-gradient-13-light.jpg",
x: 3.87,
y: 1.051,
w: 2.479,
h: 1.76,
rounding: true,
rectRadius: 0.2
});

slide.addImage({
path: "atom.svg",
x: 0.628,
y: 1.295,
w: 0.15,
h: 0.15
});

slide.addText("Card 1", {
x: 0.528,
y: 1.555,
w: 0.751,
h: 0.208,
fontSize: 14,
color: "050505",
align: "left"
});

slide.addText("Lorem ipsum dolor sit amet", {
x: 0.528,
y: 1.759,
w: 2.114,
h: 0.208,
fontSize: 12,
color: "050505",
align: "left"
});

slide.addText("Ut enim ad minim", {
x: 0.528,
y: 2.295,
w: 1.48,
h: 0.188,
fontSize: 12,
color: "050505",
align: "left"
});

slide.addText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", {
x: 4.051,
y: 1.862,
w: 2.114,
h: 0.188,
fontSize: 12,
color: "050505",
align: "left"
});

slide.addImage({
path: "https://files.chroniclehq.com/card-background-v2/thumbnail/v2-image-architecture-01.jpg",
x: 6.893,
y: 1.169,
w: 1.992,
h: 2.755,
sizing: {
type: "crop",
w: 1.992,
h: 2.755
},
rounding: true,
rectRadius: 0.2
});

slide.addShape(pptx.ShapeType.roundRect, {
x: 0.528, // Horizontal position in inches
y: 3.212, // Vertical position in inches
w: 2.5, // Width in inches
h: 2.0, // Height in inches
fill: { color: "000000", transparency: 92 },
rectRadius: 0.2
});

slide.addImage({
path: "acorn.svg",
x: 0.628,
y: 3.3,
w: 0.15,
h: 0.15
});

slide.addText("Card 3", {
x: 0.528,
y: 3.669,
w: 0.751,
h: 0.208,
fontSize: 14,
color: "050505",
align: "left"
});

slide.addText("Lorem ipsum dolor sit amet", {
x: 0.528,
y: 3.925,
w: 2.114,
h: 0.208,
fontSize: 12,
color: "050505",
align: "left"
});

slide.addText("Ut enim ad minim", {
x: 0.528,
y: 4.751,
w: 1.48,
h: 0.188,
fontSize: 12,
color: "050505",
align: "left"
});




const exportName = "Image_With_Rounding";
pptx.writeFile({ fileName: exportName })
.then((fileName) => {
console.log(`Presentation exported: ${fileName}`);
})
.catch((err) => {
console.error(`ERROR: ${err}`);
});

1 change: 1 addition & 0 deletions atom.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/core-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,14 @@ export interface ImageProps extends PositionProps, DataOrPathProps, ObjectNamePr
* @default false
*/
rounding?: boolean
/**
* Rounded rectangle corner radius (only when rounding is true)
* - values: 0.0 to 1.0 (0.0 = no rounding, 1.0 = maximum rounding)
* @default undefined (uses default PowerPoint rounding)
* @example 0.2 // 20% corner radius
* @example 0.5 // 50% corner radius
*/
rectRadius?: number
/**
* Shadow Props
* - MS-PPT > Format Picture > Shadow
Expand Down
1 change: 1 addition & 0 deletions src/gen-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ export function addImageDefinition(target: PresSlide, opt: ImageProps): void {
h: intHeight || 1,
altText: opt.altText || '',
rounding: typeof opt.rounding === 'boolean' ? opt.rounding : false,
rectRadius: opt.rectRadius,
sizing,
placeholder: opt.placeholder,
rotate: opt.rotate || 0,
Expand Down
13 changes: 12 additions & 1 deletion src/gen-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,18 @@ function slideObjectToXml (slide: PresSlide | SlideLayout): string {
strSlideXml += ` <a:off x="${x}" y="${y}"/>`
strSlideXml += ` <a:ext cx="${imgWidth}" cy="${imgHeight}"/>`
strSlideXml += ' </a:xfrm>'
strSlideXml += ` <a:prstGeom prst="${rounding ? 'ellipse' : 'rect'}"><a:avLst/></a:prstGeom>`
if (rounding) {
strSlideXml += ` <a:prstGeom prst="roundRect"><a:avLst>`
if (slideItemObj.options.rectRadius !== undefined) {
// Calculate adjustment value: rectRadius is 0.0-1.0 (ratio), convert to Office Open XML adjustment value
// (rectRadius * EMU * 100000) / min(width, height)
const adjValue = Math.round((slideItemObj.options.rectRadius * EMU * 100000) / Math.min(imgWidth, imgHeight))
strSlideXml += `<a:gd name="adj" fmla="val ${adjValue}"/>`
}
strSlideXml += `</a:avLst></a:prstGeom>`
} else {
strSlideXml += ` <a:prstGeom prst="rect"><a:avLst/></a:prstGeom>`
}

// EFFECTS > SHADOW: REF: @see http://officeopenxml.com/drwSp-effects.php
if (slideItemObj.options.shadow && slideItemObj.options.shadow.type !== 'none') {
Expand Down