有没有办法以编程方式在模板图像上叠加文本并创建输出图像文件(PNG或JPEG)?

时间:2017-05-24 12:42:16

标签: c# node.js image-processing

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

我有一个模板图片,其中包含占位符。我想用来自后端系统的实际用户信息文本替换这些占位符,并将其作为图像(PNG,JPG)呈现给用户。

是否有API可以执行此操作?即使是c#或NodeJS代码也足够了

提前致谢

2 个答案:

答案 0 :(得分:1)

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

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);
} 

答案 1 :(得分:0)

当然可以。您可以从nodejs使用GraphicsMagick:http://aheckmann.github.io/gm/ 以下是命令示例:

rewrite Hm

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