Skip to content

Images are rendered as gray placeholders instead of being embedded in PPTX #5

Description

@yexiyue

Description

When using Image::from_bytes() or Image::from_path() with SlideContent::add_image(), the generated PPTX file contains gray placeholder rectangles with a 📷 emoji and filename text, instead of the actual embedded images.

Steps to Reproduce

use ppt_rs::generator::{create_pptx_with_content, Image, SlideContent};

let image_bytes = std::fs::read("photo.png").unwrap();
let img = Image::from_bytes(image_bytes, 7_600_000, 5_700_000, "PNG")
    .position(700_000, 1_600_000);

let slide = SlideContent::new("My Slide").add_image(img);
let pptx = create_pptx_with_content("Test", vec![slide]).unwrap();
std::fs::write("output.pptx", pptx).unwrap();

Opening output.pptx in PowerPoint shows a gray rectangle with text 📷 image_xxx.png instead of the actual image.

Root Cause

The library has all the correct building blocks for image embedding, but they are not wired together in the builder pipeline:

  1. images_xml.rs — Has correct implementations:

    • generate_image_xml() — generates proper <p:pic> with <a:blip r:embed="rIdN"/>
    • generate_image_relationship() — generates image relationship XML
    • generate_image_content_type() — generates content type entries
  2. slide_xml/content.rsrender_additional_content() calls generate_image_placeholder() which creates a gray <p:sp> shape with <a:solidFill><a:srgbClr val="E0E0E0"/> instead of calling generate_image_xml().

  3. builder.rs — The builder never:

    • Calls image.get_bytes() to retrieve image data
    • Writes image bytes to ppt/media/imageN.ext in the ZIP
    • Adds image relationships (<Relationship ... Type=".../image" .../>) to slide .rels files
    • Adds image content type defaults (<Default Extension="png" ContentType="image/png"/>) to [Content_Types].xml

Expected Behavior

The generated PPTX should contain:

  • <p:pic> elements with <a:blip r:embed="rIdN"/> in slide XML (not gray <p:sp> placeholders)
  • Actual image bytes in ppt/media/imageN.ext
  • Image relationships in ppt/slides/_rels/slideN.xml.rels
  • Image MIME type entries in [Content_Types].xml

Suggested Fix

In render_additional_content() (content.rs), replace the call to generate_image_placeholder() with generate_image_xml() from images_xml.rs, and add image embedding logic to builder.rs:

  1. Replace generate_image_placeholder() with generate_image_xml() in content.rs
  2. In builder.rs, iterate slide images, call image.get_bytes(), and write to ppt/media/
  3. Add image relationships to each slide's .rels file (using generate_image_relationship())
  4. Add image content type defaults to [Content_Types].xml (using generate_image_content_type())

Environment

  • ppt-rs version: 0.2.6
  • Rust edition: 2024

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