Add: Script to padding to tilemaps
This commit is contained in:
parent
a2223fb344
commit
aa2915f080
1 changed files with 45 additions and 0 deletions
45
ShellScripts/tilemap-add-padding.sh
Executable file
45
ShellScripts/tilemap-add-padding.sh
Executable file
|
@ -0,0 +1,45 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Input parameters
|
||||
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
|
||||
|
||||
# Get the dimensions of the input image
|
||||
image_width=$(identify -format "%w" "$input_image")
|
||||
image_height=$(identify -format "%h" "$input_image")
|
||||
|
||||
# Calculate the number of tiles in both directions
|
||||
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))
|
||||
|
||||
# Create a blank canvas with a transparent background
|
||||
convert -size "${new_width}x${new_height}" xc:none blank_canvas.png
|
||||
|
||||
# Iterate through each tile in the tilemap
|
||||
for ((y = 0; y < tiles_down; y++)); do
|
||||
for ((x = 0; x < tiles_across; x++)); do
|
||||
# Extract the tile from the original image
|
||||
tile_x=$((x * tile_width))
|
||||
tile_y=$((y * tile_height))
|
||||
convert "$input_image" -crop "${tile_width}x${tile_height}+$tile_x+$tile_y" "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)))
|
||||
composite -geometry "+${new_tile_x}+${new_tile_y}" "tile_${x}_${y}.png" blank_canvas.png blank_canvas.png
|
||||
done
|
||||
done
|
||||
|
||||
# Save the final image
|
||||
mv blank_canvas.png "$output_image"
|
||||
|
||||
# Clean up temporary tiles
|
||||
rm tile_*.png
|
||||
|
||||
echo "Output saved to $output_image"
|
Loading…
Reference in a new issue