Commit 598dfc25 by Edgar Hipp

added possibility to get the size from a buffer

parent 1374c98e
...@@ -28,6 +28,10 @@ class ImageModule ...@@ -28,6 +28,10 @@ class ImageModule
.getInnerTag(templaterState) .getInnerTag(templaterState)
.getOuterXml(outsideElement) .getOuterXml(outsideElement)
xmlTemplater.replaceXml(subContent,text) xmlTemplater.replaceXml(subContent,text)
convertPixelsToEmus:(pixel)->
Math.round(pixel * 9525)
getSizeFromData:(imgData)->
[150,150]
handle:(type,data)-> handle:(type,data)->
if type=='replaceTag' and data=='image' if type=='replaceTag' and data=='image'
scopeManager=@manager.getInstance('scopeManager') scopeManager=@manager.getInstance('scopeManager')
...@@ -41,25 +45,27 @@ class ImageModule ...@@ -41,25 +45,27 @@ class ImageModule
imgData=fs.readFileSync(imgName) imgData=fs.readFileSync(imgName)
catch e catch e
return @replaceBy('<w:t></w:t>','w:t') return @replaceBy('<w:t></w:t>','w:t')
rId=@imgManager rId=@imgManager
.loadImageRels() .loadImageRels()
.addImageRels(@getNextImageName(),imgData) .addImageRels(@getNextImageName(),imgData)
sizePixel=@getSizeFromData(imgData)
size=[@convertPixelsToEmus(sizePixel[0]),@convertPixelsToEmus(sizePixel[1])]
if @options.centered==false if @options.centered==false
outsideElement='w:t' outsideElement='w:t'
newText=@getImageXml(rId) newText=@getImageXml(rId,size)
if @options.centered==true if @options.centered==true
outsideElement='w:p' outsideElement='w:p'
newText=@getImageXmlCentered(rId) newText=@getImageXmlCentered(rId,size)
@replaceBy(newText,outsideElement) @replaceBy(newText,outsideElement)
null null
getImageXml:(rId)-> getImageXml:(rId,size)->
return """ return """
<w:drawing> <w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0"> <wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="1905000" cy="1905000"/> <wp:extent cx="#{size[0]}" cy="#{size[1]}"/>
<wp:effectExtent l="0" t="0" r="0" b="0"/> <wp:effectExtent l="0" t="0" r="0" b="0"/>
<wp:docPr id="2" name="Image 2" descr="image"/> <wp:docPr id="2" name="Image 2" descr="image"/>
<wp:cNvGraphicFramePr> <wp:cNvGraphicFramePr>
...@@ -106,7 +112,7 @@ class ImageModule ...@@ -106,7 +112,7 @@ class ImageModule
</wp:inline> </wp:inline>
</w:drawing> </w:drawing>
""" """
getImageXmlCentered:(rId)-> getImageXmlCentered:(rId,size)->
""" """
<w:p> <w:p>
<w:pPr> <w:pPr>
...@@ -116,7 +122,7 @@ class ImageModule ...@@ -116,7 +122,7 @@ class ImageModule
<w:rPr/> <w:rPr/>
<w:drawing> <w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0"> <wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="2060575" cy="1939290"/> <wp:extent cx="#{size[0]}" cy="#{size[1]}"/>
<wp:docPr id="0" name="Picture" descr=""/> <wp:docPr id="0" name="Picture" descr=""/>
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"> <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment