【问题标题】:Merge two images with nodejs and graphicsmagick使用 nodejs 和 graphicsmagick 合并两个图像
【发布时间】:2013-02-07 17:33:31
【问题描述】:
我被要求根据以下要求从给定图像(可以是任何大小)创建 450 像素 x 225 像素的图像。
如果图像是 450x225,没有问题,只需保存即可。如果图像更大,只需让用户能够裁剪图像。我可以做到以上两点,但我卡住的地方是图像小于 450x225。当较小时,我想创建一个 450x225 的图像并将给定的图像粘贴到 450x225 的中心。
我正在使用 node.js 并为 node.js 使用 GraphicsMagicks 库。
非常感谢任何帮助!
【问题讨论】:
标签:
node.js
graphicsmagick
【解决方案1】:
gm convert inputfile -gravity center -extent 450x225 outputfile
如果您想轻松与 node.js 集成,可以使用 stdin/stdout 作为文件:
gm convert - - 重心 -extent 450x225 -
然后,您可以通过管道将图像数据传入和传出 gm 进程。