From 1357a30650e6eef8a857b3c3d2bb8fd8153a16c2 Mon Sep 17 00:00:00 2001 From: Aroy-Art Date: Tue, 7 Jan 2025 13:26:10 +0100 Subject: [PATCH] ShellScripts: add option size option --- ShellScripts/tilemap-add-padding.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ShellScripts/tilemap-add-padding.sh b/ShellScripts/tilemap-add-padding.sh index f100dfa..3bcf5c0 100755 --- a/ShellScripts/tilemap-add-padding.sh +++ b/ShellScripts/tilemap-add-padding.sh @@ -5,6 +5,7 @@ input_image="$1" # Input tilemap image output_image="$2" # Output image with transparent pixels tile_width="$3" # Width of each tile tile_height="$4" # Height of each tile +tile_padding="$5" # Padding between tiles # Get the dimensions of the input image image_width=$(magick identify -format "%w" "$input_image") @@ -15,8 +16,8 @@ tiles_across=$((image_width / tile_width)) tiles_down=$((image_height / tile_height)) # New image size (considering the 1 pixel padding between tiles) -new_width=$((tiles_across * (tile_width + 1) - 1)) -new_height=$((tiles_down * (tile_height + 1) - 1)) +new_width=$((tiles_across * (tile_width + tile_padding) - tile_padding)) +new_height=$((tiles_down * (tile_height + tile_padding) - tile_padding)) # Create a blank canvas with a transparent background and enforce the correct color space magick -size "${new_width}x${new_height}" xc:none -colorspace sRGB blank_canvas.png @@ -32,8 +33,8 @@ for ((y = 0; y < tiles_down; y++)); do magick "$input_image" -crop "${tile_width}x${tile_height}+$tile_x+$tile_y" -colorspace sRGB "tile_${x}_${y}.png" # Place the tile on the new image, accounting for the 1-pixel padding - new_tile_x=$((x * (tile_width + 1))) - new_tile_y=$((y * (tile_height + 1))) + new_tile_x=$((x * (tile_width + tile_padding))) + new_tile_y=$((y * (tile_height + tile_padding))) # Composite the tile onto the new canvas, ensuring color space is preserved magick composite -geometry "+${new_tile_x}+${new_tile_y}" "tile_${x}_${y}.png" -colorspace sRGB blank_canvas.png blank_canvas.png