Thanks to @TheincredibleJan and @GilbertLeBlanc.
The solution I got was generating x images (one per word) and merge them into a big image.
The code is below (change the numbers as you need depending on the size or type of your own images):
String frase = "i ate pizza last night";
int len = frase.replace(" ", "").length();
String[] words = frase.split(" ");
BufferedImage result = new BufferedImage((len * 25) + 10, 50, BufferedImage.TYPE_INT_ARGB);
Graphics g = result.getGraphics();
int x = 0;
for (int i = 0; i < words.length; i++) {
CaptchaGenerator captchagen = new CaptchaGenerator();
Captcha captcha = captchagen.createCaptcha(words[i].length() * 25 + 3, 50, words[i]);
BufferedImage imagen = captcha.getImage();
g.drawImage(imagen, x, 0, null);
x += imagen.getWidth() - 5;
}
g.dispose();
try {
File outputfile = new File("captchaResult.png");
ImageIO.write(result, "png", outputfile);
} catch (Exception ex) {
}
And this is the generated image:
CAPTCHA image result