@@ -418,6 +418,13 @@ class DocxPostProcessor extends Processor {
418418 return drawing ;
419419 }
420420
421+ // Extract original dimensions and other properties to preserve
422+ const extentMatch = / < w p : e x t e n t c x = " ( \d + ) " c y = " ( \d + ) " / . exec (
423+ drawing
424+ ) ;
425+ const originalCx = extentMatch ? extentMatch [ 1 ] : null ;
426+ const originalCy = extentMatch ? extentMatch [ 2 ] : null ;
427+
421428 const [ , extension ] = mime . split ( "/" ) ;
422429 let newRelationshipId = this . relationshipMap . get ( imageUrl ) ;
423430 if ( ! newRelationshipId ) {
@@ -460,7 +467,7 @@ class DocxPostProcessor extends Processor {
460467 ) ;
461468 }
462469
463- // Create updated drawing with new relationship ID
470+ // Create updated drawing with new relationship ID but preserve dimensions
464471 const updatedDrawing = drawing
465472 . replace ( / ( t i t l e | d e s c r ) = " [ ^ " ] * " / g, '$1=""' )
466473 . replace ( / e m b e d = " [ ^ " ] + " / g, `embed="${ newRelationshipId } "` ) ;
@@ -598,10 +605,6 @@ class DocxPostProcessor extends Processor {
598605 <w:next w:val="TextBody"/>
599606 <w:qFormat/>
600607 <w:pPr>
601- <w:numPr>
602- <w:ilvl w:val="0"/>
603- <w:numId w:val="1"/>
604- </w:numPr>
605608 <w:spacing w:before="240" w:after="120"/>
606609 <w:outlineLvl w:val="0"/>
607610 </w:pPr>
@@ -703,6 +706,12 @@ class OdpPostProcessor extends Processor {
703706 return drawFrame ;
704707 }
705708
709+ // Extract original dimensions to preserve aspect ratio
710+ const widthMatch = / s v g : w i d t h = " ( [ ^ " ] + ) " / . exec ( drawFrame ) ;
711+ const heightMatch = / s v g : h e i g h t = " ( [ ^ " ] + ) " / . exec ( drawFrame ) ;
712+ const originalWidth = widthMatch ? widthMatch [ 1 ] : null ;
713+ const originalHeight = heightMatch ? heightMatch [ 1 ] : null ;
714+
706715 const [ , extension ] = mime . split ( "/" ) ;
707716 const [ basename , newfile ] = this . filestore . fileBaseName ( content ) ;
708717 const imgFile = `Pictures/${ basename } .${ extension } ` ;
@@ -730,9 +739,11 @@ class OdpPostProcessor extends Processor {
730739
731740 // Ensure the image is actually displayed
732741 if ( ! updatedDrawFrame . includes ( "<draw:image" ) ) {
742+ // Preserve original dimensions if available
743+ const imageTag = `<draw:image xlink:href="${ imgFile } " xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>` ;
733744 updatedDrawFrame = updatedDrawFrame . replace (
734745 / < d r a w : f r a m e / ,
735- `<draw:frame><draw:image xlink:href=" ${ imgFile } " xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> `
746+ `<draw:frame>${ imageTag } `
736747 ) ;
737748 }
738749
0 commit comments