Files
noise-fields/frontend/scripts/tile.sh
T

37 lines
1001 B
Bash
Executable File

#!/bin/bash
INPUT="$1"
OUTPUT_DIR="tiles"
#Create OUTPUT_DIR if it doesn't exist
mkdir -p "$OUTPUT_DIR"
#Get image dimensions
WIDTH=$(identify -format "%w" "$INPUT")
HEIGHT=$(identify -format "%h" "$INPUT")
echo "Image dimensions: $WIDTH x $HEIGHT"
#Tile dimensions
TILE_WIDTH=8192
TILE_HEIGHT=4096
echo "Cutting image into tiles of ${TILE_WIDTH}x${TILE_HEIGHT}..."
# Loop over vertical and horizontal positions
count=0
for (( y=0; y<HEIGHT; y+=TILE_HEIGHT )); do
for (( x=0; x<WIDTH; x+=TILE_WIDTH )); do
W=$(($TILE_WIDTH < $((WIDTH - x)) ? $TILE_WIDTH : $((WIDTH - x))))
H=$(($TILE_HEIGHT < $((HEIGHT - y)) ? $TILE_HEIGHT : $((HEIGHT - y))))
# Filename encodes position: tile_x<x>_y<y>_w<W>_h<H>.png
TILE_FILE="$OUTPUT_DIR/tile_x${x}_y${y}_w${W}_h${H}.png"
echo "Creating $TILE_FILE"
convert "$INPUT" -crop "${TILE_WIDTH}x${TILE_HEIGHT}+${x}+${y}" +repage "$TILE_FILE"
((count++))
done
done
echo "Done. $count tiles created."