Skip to content

Commit

Permalink
Headless rotate fix (qzind#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf authored Apr 22, 2023
1 parent a4cebe5 commit 2afb609
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/qz/printer/action/PrintImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 2afb609

Please sign in to comment.