ReferenceError:使用Watermarkjs时未定义图像

时间:2019-01-08 07:09:33

标签: javascript node.js express watermark

我给出了文件存在的特定路径,但是在使用watermarkjs时出现了错误

watermark(['../uploads/file_1546929350511_Name.PNG']).image(text.center('watermrk.js', '48px Josefin Slab', '#fff', 0.5)).then(function (img) { document.getElementById('center').appendChild(img); });

错误是

C:\Users\Admin\Desktop\Nss testing\test\node_modules\watermarkjs\dist\watermark.js:351
      var img = new Image();
                ^ReferenceError: Image is not defined
at loadUrl (C:\Users\Admin\Desktop\Nss testing\test\node_modules\watermarkjs\dist\watermark.js:351:14)
at load (C:\Users\Admin\Desktop\Nss testing\test\node_modules\watermarkjs\dist\watermark.js:337:20)
at watermark (C:\Users\Admin\Desktop\Nss testing\test\node_modules\watermarkjs\dist\watermark.js:164:42)
at C:\Users\Admin\Desktop\Nss testing\test\controller\updateController.js:60:7
at Array.<anonymous> (C:\Users\Admin\Desktop\Nss testing\test\node_modules\multer\lib\make-middleware.js:53:37)
at listener (C:\Users\Admin\Desktop\Nss testing\test\node_modules\on-finished\index.js:169:15)
at onFinish (C:\Users\Admin\Desktop\Nss testing\test\node_modules\on-finished\index.js:100:5)
at callback (C:\Users\Admin\Desktop\Nss testing\test\node_modules\ee-first\index.js:55:10)
at IncomingMessage.onevent (C:\Users\Admin\Desktop\Nss testing\test\node_modules\ee-first\index.js:93:5)
at emitNone (events.js:106:13)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

1 个答案:

答案 0 :(得分:1)

似乎应在浏览器中使用WatermarkJS模块。

从您的问题主题(express,node.js)看来,您正在尝试在服务器端使用它。

Image是窗口对象上的全局对象,它创建要在DOM中使用或预加载图像资产的新图像。这就是为什么错误显示为ReferenceError: Image is not defined的原因。

我建议您检查一下ImageMagick模块,该模块可以在服务器端使用。