Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试在javascript中实现imagemagick.js功能;如何使用Processing.js识别和转换图像?_Javascript_Image_Process_Imagemagick_Processing.js - Fatal编程技术网

尝试在javascript中实现imagemagick.js功能;如何使用Processing.js识别和转换图像?

尝试在javascript中实现imagemagick.js功能;如何使用Processing.js识别和转换图像?,javascript,image,process,imagemagick,processing.js,Javascript,Image,Process,Imagemagick,Processing.js,我在Chrome上遇到了一个问题,它用红色覆盖层打印我网站上的灰度图像。这是一个已知的Chrome错误,应该已经修复,但在修复之前,我需要找到一种方法使我的图像正确打印。我在一条关于imagemagick的帖子中发现了这个漏洞: im.identify(['-format', '%wx%h', '@Model.DatabaseName' + '.jpg'], function(err, output) { if (err) throw err; // if output retu

我在Chrome上遇到了一个问题,它用红色覆盖层打印我网站上的灰度图像。这是一个已知的Chrome错误,应该已经修复,但在修复之前,我需要找到一种方法使我的图像正确打印。我在一条关于imagemagick的帖子中发现了这个漏洞:

im.identify(['-format', '%wx%h', '@Model.DatabaseName' + '.jpg'], function(err, output) {
    if (err) throw err;
    // if output returns PsuedoClass Gray, do im.convert
});
我发现这种情况发生在灰度JPG上。使用imagemagick,我能够使用以下命令对图像进行大规模重新处理,以避免出现此问题

如果
identify-format“%r”file.jpg
返回“PsuedoClass Gray”或“PsuedoClass Gray” 然后运行以下命令:
convert file.jpg-type Truecolor file.jpg

但是,I imagemagick.js不起作用;我尝试使用它,但出现了一个错误“require is not defined”,并发现我无法在浏览器中使用node.js脚本。显然,Processing.js应该是一个相当不错的javascript库来模仿imagemagick,但我不知道如何做同样的事情。这就是我试图用imagemagick所做的:

im.identify(['-format', '%wx%h', '@Model.DatabaseName' + '.jpg'], function(err, output) {
    if (err) throw err;
    // if output returns PsuedoClass Gray, do im.convert
});

如何使用Processing.js执行此操作,或者是否有其他库可用于执行此操作?

您最好的解决方法是在服务器上更改将原始颜色jpeg转换为黑白的代码。如果您已经在使用ImageMagick
convert
执行此任务,更多的命令行参数将为您提供一个包含黑白图像的Truecolor文件。您不需要在第二次
转换时执行此操作

对于基于浏览器的解决方案来说,processing.js是一种过分的技术。这对我很有用:

<!doctype html>
<html><head></head><body>
<img src="http://www.oceanstatejoblot.com/_images/coupon/049683_Final.jpg"> Final.jpg<br><br>
<img id="bw1" src="http://www.oceanstatejoblot.com/_images/coupon/049683_BW.jpg"> BW.jpg<br><br>
<canvas id="bw2" width="352" height="245"></canvas> Canvas<br>
<script>
window.onload = function() {
  document.getElementById("bw2").getContext("2d").drawImage(document.getElementById("bw1"), 0, 0);
};
</script>
</body></html>

Final.jpg

BW.jpg

画布
window.onload=函数(){ document.getElementById(“bw2”).getContext(“2d”).drawImage(document.getElementById(“bw1”),0,0); };
Chrome打印预览:


您提到“无法在我的浏览器中使用node.js”。你是说你的服务器吗?您试图在哪里运行
convert
?我查看了你的图像,在我的Chrome版本39.0.2171.95m中它看起来很好<代码>识别
将其报告为伪灰色。如果您尝试打印该图像,它将以红色打印