svg在node.js中使用imagemagick进行png转换 [英] svg to png convertion with imagemagick in node.js

查看:651
本文介绍了svg在node.js中使用imagemagick进行png转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在nodejs中搜索一个方法,在imagemagick https://的帮助下将svg转换为png github.com/rsms/node-imagemagick ,不将生成的png存储在本地文件系统的临时文件中。

I am search a way in nodejs to convert an svg to png with the help of imagemagick https://github.com/rsms/node-imagemagick, without storing the resulting png in a temp file on the local filesystem.

不幸的是,我无法做到这个。我没有在互联网上找到榜样。有人可以举个例子吗?

Unfortunately, I am unable to do this. And I didn't find example in the internet. Can someone give me an example?

推荐答案

oI找到了我要找的东西。基本上,我想出了如何将数据传输到转换执行的std :: in。这使我可以在不访问本地文件系统的情况下转换图像。

oI found what I am looking for. Basically, I figured out how to pipe data into the std::in of the convert execution. This makes it possible for me to convert images without accessing the local file system.

这是我的演示代码:

var im = require('imagemagick');
var fs = require('fs');

var svg = fs.readFileSync('/somepath/svg.svg', 'utf8');                

var conv = im.convert(['svg:-', 'png:-'])
conv.on('data', function(data) {
  console.log('data');
  console.log(data);
}); 
conv.on('end', function() {
  console.log('end');
});                                                                                
conv.stdin.write(svg);
conv.stdin.end();

这篇关于svg在node.js中使用imagemagick进行png转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆