import math from PIL import Image def convert_tile_to_half_drop(original_image): # Create a 3x3 grid size, _ = original_image.size grid_size = (3, 3) grid_image = Image.new('RGB', (size * grid_size[0], size * grid_size[1])) for i in range(grid_size[0]): for j in range(grid_size[1]): grid_image.paste(original_image, (i * size, j * size)) # Rotate the grid 45 degrees rotated_grid = grid_image.rotate(45, expand=True) # Calculate the cropping coordinates for a 2048x2048 center square center = rotated_grid.size[0] // 2, rotated_grid.size[1] // 2 crop_box = (center[0] - size, center[1] - size, center[0] + size, center[1] + size) cropped_image = rotated_grid.crop(crop_box) # Crop the 724x1448 from the top-left new_height = round(math.sqrt(2 * size ** 2)) new_width = round(new_height // 2) final_crop = cropped_image.crop((0, 0, new_width, new_height)) return final_crop def generate_tile_test_arrangement(original_image): # Dimensions of the original image width, height = original_image.size canvas_width = width * 3 canvas_height = height * 2 # Create a new blank image (canvas) canvas = Image.new('RGB', (canvas_width, canvas_height), (255, 255, 255)) # White background # Paste the first image (column 1, vertically centered) canvas.paste(original_image, (0, (canvas_height - height) // 2)) # Paste two images (column 2) canvas.paste(original_image, (width, 0)) # Top canvas.paste(original_image, (width, height)) # Bottom # Paste the third image (column 3, vertically centered) canvas.paste(original_image, (2 * width, (canvas_height - height) // 2)) return canvas def prepare_for_diamond_drop(original_image): width, height = original_image.size canvas_width = width * 2 canvas_height = height * 2 canvas = Image.new('RGB', (canvas_width, canvas_height), (255, 255, 255)) # Column 1 canvas.paste(original_image, (0, 0)) canvas.paste(original_image, (0, height)) # Column 2 canvas.paste(original_image, (width, 0)) canvas.paste(original_image, (width, height)) return canvas # repeat the image, 2x2. # crop from the center, 1x1.