在C ++ / Java / Python库中是否有任何简单的PHP函数imagettftext()?
答案 0 :(得分:0)
你可以使用PIL
:
from PIL import Image, ImageDraw, ImageFont
font = ImageFont.truetype("/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf", 18)
img = Image.open("test.jpg")
draw = ImageDraw.Draw(img)
draw.text((40, 40), "...sample text...", font=font, fill="red")
img.show()
在java中,你可以简单地在任何java.awt.Image
实例上绘图:
import javax.imageio.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.*;
public class ImageTest {
public static void main(String args[]) throws Exception {
BufferedImage img = ImageIO.read(new File("test.jpg"));
Graphics2D g = img.createGraphics();
Font f = Font.createFont(
Font.TRUETYPE_FONT,
new File("/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf")
).deriveFont(18f);
g.setFont(f);
g.setColor(Color.RED);
g.drawString("test string", 40, 40);
JFrame jf = new JFrame("test");
jf.add(new JLabel(new ImageIcon(img)));
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
jf.pack();
}
}
对于c ++,有很多图像库(imagemagick-bindings,CImg,...)