JAVA 59
Untitled Guest on 27th September 2019 02:08:04 PM
  1.  Graphics2D g2d = img.createGraphics();
  2.         g2d.drawImage(img, 0, 0, null);
  3.         g2d.drawImage(img, 0, 0, null);
  4.         g2d.setPaint(textColor);
  5.         int fontSize = rnd.nextInt(18) + 36;
  6.        // g2d.setFont(new Font("Serif", Font.BOLD, fontSize));
  7.            try {
  8.         g2d.setFont(Font.createFont(Font.TRUETYPE_FONT, new File("/root/fonts/DejaVuSerif-Bold.ttf")));
  9.                 } catch (Exception e) {
  10.                 e.printStackTrace();
  11.                 }
  12.                 FontMetrics fm = g2d.getFontMetrics();
  13.         int x2 = img.getWidth() - fm.stringWidth(text) - rnd.nextInt(120 - fontSize);
  14.         if (fontSize < 12) {
  15.             fontSize = 12;
  16.         }
  17.         int y2 = fm.getHeight() - (fontSize / 4);//about 4
  18.         g2d.drawString(text, x2, y2);
Raw Paste

Login or Register to edit or fork this paste. It's free.