Skip to content

ImageRun produces incorrect EMU dimensions — images invisible in Word for Mac #3421

@perekskog

Description

@perekskog

Bug Report

Library version

docx 9.6.1

Problem

ImageRun with transformation: { width, height } produces wildly incorrect EMU dimensions when large pixel values are used.

The transformation property expects pixel values and multiplies by 9525 to convert to EMU. However, if you accidentally pass an EMU-sized number as pixels (e.g. width: 5029200 intending 5.5 inches), the value gets multiplied again to cx="47903130000" — equivalent to ~52,000 inches.

Symptoms

-[Word for Mac 16.107] refuses to open the .docx file entirely

  • Google Docs opens the file but shows a black square instead of the image
  • The Claude.ai preview pane shows no image

Root cause

The XML produced contains:

<wp:extent cx="47903130000" cy="26945510625"/>

Which is ~52,000 inches wide. The correct value for a 5.5" image is:

<wp:extent cx="5029200" cy="2828925"/>

Workaround

Use small pixel values (e.g. width: 528, height: 297 for a 5.5" image at 96 DPI), or patch the EMU values directly in the XML after document generation.

Suggested fix

Add validation or documentation warning when transformation values exceed a reasonable pixel range (e.g. > 10000 pixels should trigger a warning).

Discovered while building a document with three embedded JPEG images using Claude AI and docx 9.6.1.

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