private BufferedImage rotateImage(BufferedImage img) throws IOException {
int width = img.getWidth();
int height = img.getHeight();
BufferedImage newImage;
double[][] newPositions = new double[4][];
newPositions[0] = this.calculatePosition(0, 0);
newPositions[1] = this.calculatePosition(width, 0);
newPositions[2] = this.calculatePosition(0, height);
newPositions[3] = this.calculatePosition(width, height);
double minX = Math.min(Math.min(newPositions[0][0], newPositions[1][0]), Math.min(newPositions[2][0], newPositions[3][0]));
double maxX = Math.max(Math.max(newPositions[0][0], newPositions[1][0]), Math.max(newPositions[2][0], newPositions[3][0]));
double minY = Math.min(Math.min(newPositions[0][1], newPositions[1][1]), Math.min(newPositions[2][1], newPositions[3][1]));
double maxY = Math.max(M