Skip to content

Sizing Images #94

Closed
Closed
@Alecat

Description

@Alecat

Hi,
I am working on a document generator for files that will eventually be imported into Adobe Indesign.
Picture scaling works correctly for images when viewed in Word/OpenOffice. However when imported into InDesign the images appear at their native resolution instead.

After doing some digging I found that the issue was with the sizing of the pic:spPr element. InDesign uses these to render the image, rather than the dimensions of the Inline object's extents.

I am not sure if this is an error with python-docx or Adobe's parsing.

I was able to fix my issue by passing width and height through all add_picture/new_picture methods and then relocating the picture scaling logic (from Run's add_picture method) into InlineShape's new_picture method. Both the picture and the inlineshape can then be updated with the correct size information and the file now imports correctly into InDesign.

Does this sound like an appropriate fix? Alternatively, is it possible to access the Picture object inside the InlineShape? That would then make it be possible to modify its dimensions in add_picture.

I have not tested this extensively, nor do I pretend to really understand the docx spec. I don't know if I may have just broken other things but I can submit a pull request with changes if you want to see more clearly in code what problem I was attempting to solve.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions