From 2afb6092b1d698ad52646c5ebceace03900aec01 Mon Sep 17 00:00:00 2001 From: Tres Finocchiaro Date: Fri, 21 Apr 2023 22:21:51 -0400 Subject: [PATCH] Headless rotate fix (#1119) --- src/qz/printer/action/PrintImage.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/qz/printer/action/PrintImage.java b/src/qz/printer/action/PrintImage.java index be71845ff..aec9b489a 100644 --- a/src/qz/printer/action/PrintImage.java +++ b/src/qz/printer/action/PrintImage.java @@ -16,6 +16,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import qz.common.Constants; +import qz.common.TrayManager; import qz.printer.PrintOptions; import qz.printer.PrintOutput; import qz.utils.ConnectionUtilities; @@ -278,8 +279,13 @@ public static BufferedImage rotate(BufferedImage image, double angle, Object dit int sWidth = image.getWidth(), sHeight = image.getHeight(); int eWidth = (int)Math.floor((sWidth * cos) + (sHeight * sin)), eHeight = (int)Math.floor((sHeight * cos) + (sWidth * sin)); - GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getDefaultConfiguration(); - BufferedImage result = gc.createCompatibleImage(eWidth, eHeight, Transparency.TRANSLUCENT); + BufferedImage result; + if(!GraphicsEnvironment.isHeadless()) { + GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getDefaultConfiguration(); + result = gc.createCompatibleImage(eWidth, eHeight, Transparency.TRANSLUCENT); + } else { + result = new BufferedImage(eWidth, eHeight, Transparency.TRANSLUCENT); + } Graphics2D g2d = result.createGraphics(); g2d.setRenderingHints(buildRenderingHints(dithering, interpolation));