webshot不会在html中呈现本地图像

The*_*oon 7 html javascript node.js phantomjs

我正在使用node-webshot和phantomjs-cli将html字符串渲染为png图像.html包含图像标记.当src属性指向本地文件且未引发错误时,不会呈现图像.但是,当src指向http位置时,它会渲染图像.我已经尝试了所有我能想到的不同文件路径组合,例如

<img src=images/mushrooms.png"/>
<img src=images//mushrooms.png"/> 
<img src=c:\images\mushrooms.png"/>
<img src=c:\\images\\mushrooms.png"/>
<img src=file://c:\\images\\mushrooms.png"/>
<img src=file://images//mushrooms.png"/>
etc..
Run Code Online (Sandbox Code Playgroud)

但到目前为止还没有运气.有趣的是,它在我的同事的机器上工作正常,这台机器是Mac但不在我的机器上是Windows,我尝试使用两台不同的Windows机器但没有成功.

以下是一些关注该问题的简化代码:

'use strict'

const webshot = require('webshot');

console.log('generating');

webshot('<html><head></head><body><img src="c:\\images\\mushrooms.png"/></body></html>', 'output.png', {siteType: 'html'}, function(err) {
    console.log(err);
});

/*
webshot('<html><head></head><body><img src="https://s10.postimg.org/pr6zy8249/mushrooms.png"/></body></html>', 'output.png', {siteType: 'html'}, function(err) {  
    console.log(err);      
});
*/
Run Code Online (Sandbox Code Playgroud)

注释掉的代码块是一个使用Web链接作为图像源的示例,但我需要它来处理本地路径.

有没有人知道如何解决这个问题?

谢谢

Bla*_*Gru 4

本地文件应该可以通过 URI 方案访问file:

<img src="file:///C:/images/mushrooms.png">

根据规格

A file URL takes the form:

   file://<host>/<path>
Run Code Online (Sandbox Code Playgroud)