使用npm包gm为GIF叠加文字时仅编辑最后2帧的问题求助
使用gm包为GIF叠加文字时仅最后两帧生效
我尝试使用gm包为GIF图像叠加文字,这套功能在处理普通静态图片时可正常运行,但处理GIF时,文字只会叠加在最后2帧上。我对该包及ImageMagick的使用经验较少。
以下是我目前用来编辑图像的代码:
gm(request(image)) //任意图片URL .command('convert') .coalesce() .font("./impact.ttf") .dither(false) .fontSize(Math.round(width/11)) //width变量在代码前段已定义 .stroke("#000000") .strokeWidth(width/450) .out('-gravity', 'north') .out('-size',width+'x','-fill','white','-background', 'transparent', '0') .out('caption:' + meme[0].toUpperCase().substr(meme[0].indexOf(" ")+1)) .out('-layers','optimize') .out('-gravity', 'south') .out('-size',width+'x','caption:' + meme[1].toUpperCase()) .out('-layers','optimize') .strip() // 若使用以下两行代码,确实会追加所有图层,但文本无法像使用caption时那样自动换行 // .drawText(0,1, meme[0].toUpperCase().substr(meme[0].indexOf(" ") + 1), 'North') // .drawText(0,0, meme[1].toUpperCase(), 'South') .stream((error, stdout) => { // 流处理逻辑 })
目前代码运行的结果为生成的GIF仅最后两帧带有叠加的文字,希望能得到相关解决方案的指导。
内容的提问来源于stack exchange,提问作者ThzeTerminator
相关产品推荐
相关产品推荐

