Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
docxtemplater-image-module
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
npm
docxtemplater-image-module
Commits
598dfc25
Commit
598dfc25
authored
Dec 30, 2014
by
Edgar Hipp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added possibility to get the size from a buffer
parent
1374c98e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
7 deletions
+13
-7
coffee/index.coffee
+13
-7
No files found.
coffee/index.coffee
View file @
598dfc25
...
...
@@ -28,6 +28,10 @@ class ImageModule
.
getInnerTag
(
templaterState
)
.
getOuterXml
(
outsideElement
)
xmlTemplater
.
replaceXml
(
subContent
,
text
)
convertPixelsToEmus
:
(
pixel
)
->
Math
.
round
(
pixel
*
9525
)
getSizeFromData
:
(
imgData
)
->
[
150
,
150
]
handle
:
(
type
,
data
)
->
if
type
==
'replaceTag'
and
data
==
'image'
scopeManager
=
@
manager
.
getInstance
(
'scopeManager'
)
...
...
@@ -41,25 +45,27 @@ class ImageModule
imgData
=
fs
.
readFileSync
(
imgName
)
catch
e
return
@
replaceBy
(
'<w:t></w:t>'
,
'w:t'
)
rId
=
@
imgManager
.
loadImageRels
()
.
addImageRels
(
@
getNextImageName
(),
imgData
)
sizePixel
=
@
getSizeFromData
(
imgData
)
size
=
[
@
convertPixelsToEmus
(
sizePixel
[
0
]),
@
convertPixelsToEmus
(
sizePixel
[
1
])]
if
@
options
.
centered
==
false
outsideElement
=
'w:t'
newText
=
@
getImageXml
(
rId
)
newText
=
@
getImageXml
(
rId
,
size
)
if
@
options
.
centered
==
true
outsideElement
=
'w:p'
newText
=
@
getImageXmlCentered
(
rId
)
newText
=
@
getImageXmlCentered
(
rId
,
size
)
@
replaceBy
(
newText
,
outsideElement
)
null
getImageXml
:
(
rId
)
->
getImageXml
:
(
rId
,
size
)
->
return
"""
<w:drawing>
<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:docPr id="2" name="Image 2" descr="image"/>
<wp:cNvGraphicFramePr>
...
...
@@ -106,7 +112,7 @@ class ImageModule
</wp:inline>
</w:drawing>
"""
getImageXmlCentered
:
(
rId
)
->
getImageXmlCentered
:
(
rId
,
size
)
->
"""
<w:p>
<w:pPr>
...
...
@@ -116,7 +122,7 @@ class ImageModule
<w:rPr/>
<w:drawing>
<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=""/>
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment