I needs to modify the image (resize + add text) on the server side like this:
BufferedImage tmp = new BufferedImage(image.getWidth() + 50, image.getHeight() + 100, BufferedImage.TYPE_INT_RGB);
Graphics graphics = tmp.getGraphics();
graphics.fillRect(0, 0, canvas.getWidth(), 40);
graphics.drawImage(image, 0, 40, null);
graphics.setFont(graphics.getFont().deriveFont(25f));
graphics.setColor(Color.red);
graphics.drawString(textImage, 20, 30);
graphics.dispose();
However, I get this error
Caused by: java.awt.HeadlessException
Is there something that I forgot? Locally it works ok but on the Linux server gets an error as above.
Thanks for help.
EDIT: or is there workaround to avoid this headless exception?
EDIT2: OK I got logs from server:
Caused by: java.awt.HeadlessException
at sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(HeadlessGraphicsEnvironment.java:64)
Someone before tried do this
GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage tmp = config.createCompatibleImage(image.getWidth() + 50, image.getHeight() + 100, BufferedImage.TYPE_INT_RGB);
I met that error time ago while installing a war application on a Linux server with no graphical environment.
Starting the jvm with the -Djava.awt.headless=true
should solve your problem. Please keep in mint that if your code runs within an application server you will need to modify the application server VM whith that parameter.