import java.util.*; import java.util.zip.*; import java.util.List; import java.util.regex.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; import java.util.concurrent.locks.*; import java.util.function.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.table.*; import java.io.*; import java.net.*; import java.lang.reflect.*; import java.lang.ref.*; import java.lang.management.*; import java.security.*; import java.security.spec.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.awt.geom.*; import javax.imageio.*; import java.math.*; import java.time.Duration; import java.lang.invoke.VarHandle; import java.lang.invoke.MethodHandles; // Thanks to ChatGPT class main { static BufferedImage rotateImage(BufferedImage image, double angle) { int width = image.getWidth(); int height = image.getHeight(); // Calculate new image size to fit rotated image double radians = Math.toRadians(angle); double sin = Math.abs(Math.sin(radians)); double cos = Math.abs(Math.cos(radians)); int newWidth = (int) Math.floor(width * cos + height * sin); int newHeight = (int) Math.floor(height * cos + width * sin); // Create new image with transparent background BufferedImage rotated = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = rotated.createGraphics(); AffineTransform at = new AffineTransform(); // Translate to center of image and rotate at.translate((newWidth - width) / 2, (newHeight - height) / 2); at.rotate(radians, width / 2, height / 2); // Draw original image onto new image with transformation g2d.setTransform(at); g2d.drawImage(image, 0, 0, null); g2d.dispose(); return rotated; }}