Skip to content

Bug: Image with sizing: { type: 'crop' } renders with incorrect container size or fails #1399

@wamaw123

Description

@wamaw123

Current Behavior
When using slide.addImage with the sizing property to apply a crop, the image fails to render correctly in the output .pptx file. The image container is not rendered with the specified w and h dimensions.

Instead, it results in one of several failure modes:

A container with maximum dimensions (e.g., 254cm x 254cm) with the small, cropped image in the top-left corner.
A 0cm x 0cm object.
An error box stating "The picture can't be displayed."
This happens even when the image data is valid and all positioning/dimension parameters are hardcoded with valid numbers.

Expected Behavior
The image should be added to the slide within a container that respects the w and h parameters (e.g., 5.0 x 3.0 inches), and the crop defined in the sizing object should be applied to the image within that container.

Steps to Reproduce
This minimal HTML test case, using the latest CDN version of the library and known-good data, consistently reproduces the error.

HTML

<!DOCTYPE html>
<html>
<head>
    <title>PptxGenJS Crop Bug Reproduction</title>
    <script src="https://unpkg.com/pptxgenjs@latest/dist/pptxgen.bundle.js"></script>
</head>
<body>
    <h1>PptxGenJS Crop Bug Reproduction</h1>
    <p>Click the button to generate a PowerPoint file that demonstrates the bug.</p>
    <button onclick="runTest()">Run Test</button>

    <script>
        function runTest() {
            // 1. Create a new presentation
            let pptx = new PptxGenJS();
            let slide = pptx.addSlide();

            // 2. Define image options with hardcoded, valid data
            const imageOptions = {
                // Known-good 1x1 red pixel PNG
                data: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/wcAAwAB/epv2AAAAABJRU5ErkJggg==",
                
                // Hardcoded position and container size
                x: 1.0,
                y: 1.0,
                w: 5.0,
                h: 3.0,
                
                // Hardcoded crop settings
                sizing: {
                    type: 'crop',
                    x: 0,
                    y: 0,
                    w: 100,
                    h: 100
                }
            };

            // 3. Add the image and save
            slide.addImage(imageOptions);
            pptx.writeFile({ fileName: 'Crop_Bug_Test.pptx' });
        }
    </script>
</body>
</html>

Environment

PptxGenJS Version: Latest via CDN (unpkg.com)
Operating System: Windows 11, MS360 ppt
Browser: Edge
Additional Context
This bug was discovered after extensive debugging that ruled out implementation errors, corrupted Base64 data, and incorrect calculations. The failure of this minimal test case points to a core issue in the library's handling of the sizing property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions