有没有办法以编程方式覆盖模板图像上的文本,并创build一个输出图像文件(PNG或JPEG)?

我正在创build一个交互式程序,它接受用户input,查询后端系统并将输出返回给用户。 我想这个输出显示为一个图像。

我有一个占位符的模板图像。 我想用后台系统中的实际用户信息文本replace这些占位符,并以图像(PNG,JPG)的forms呈现给用户。

有没有这样的API? 即使ac#或NodeJS代码在这一点上也足够了

提前致谢

是的,如果您在Windows窗体中,则可以使用System.Drawing命名空间中的Graphics.DrawString方法将文本绘制到任何graphics上下文中。 这种强大的方法可以完全控制字体,位置,笔刷等。 Microsoft文档下面是一些示例代码:

public void DrawStringPointF(PaintEventArgs e) { // Create string to draw. String drawString = "Sample Text"; // Create font and brush. Font drawFont = new Font("Arial", 16); SolidBrush drawBrush = new SolidBrush(Color.Black); // Create point for upper-left corner of drawing. PointF drawPoint = new PointF(150.0F, 150.0F); // Draw string to screen. e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint); } 

当然。 你可以使用GraphicsMagick来从nodejs中获取: http ://aheckmann.github.io/gm/下面是命令的例子:

 gm convert -font helvetica -fill blue -pointsize 36 -draw "text 15,50 'hello'" source.jpg destination.jpg 

从这里取: https : //gist.github.com/wellsie/9bcfeb9f2b3869e5e555c926e4f2c0e2