Commit 23c13534 by Edgar Hipp

added getImageFromData method

parent b476346c
...@@ -32,24 +32,26 @@ class ImageModule ...@@ -32,24 +32,26 @@ class ImageModule
Math.round(pixel * 9525) Math.round(pixel * 9525)
getSizeFromData:(imgData)-> getSizeFromData:(imgData)->
[150,150] [150,150]
getImageFromData:(imgData)->
fs.readFileSync(imgData)
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')
templaterState=@manager.getInstance('templaterState') templaterState=@manager.getInstance('templaterState')
tag = templaterState.textInsideTag.substr(1) tag = templaterState.textInsideTag.substr(1)
imgName=scopeManager.getValueFromScope(tag) imgData=scopeManager.getValueFromScope(tag)
if imgName=='undefined' then return @replaceBy('<w:t></w:t>','w:t') if imgData=='undefined' then return @replaceBy('<w:t></w:t>','w:t')
try try
imgData=fs.readFileSync(imgName) imgBuffer=@getImageFromData(imgData)
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(),imgBuffer)
sizePixel=@getSizeFromData(imgData) sizePixel=@getSizeFromData(imgBuffer)
size=[@convertPixelsToEmus(sizePixel[0]),@convertPixelsToEmus(sizePixel[1])] size=[@convertPixelsToEmus(sizePixel[0]),@convertPixelsToEmus(sizePixel[1])]
if @options.centered==false if @options.centered==false
......
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