Created
February 21, 2025 08:45
-
-
Save jasalt/7edee658e2da4de331078455ad135e56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
input_image="full.jpg" | |
output_prefix="part_" | |
max_width=3840 | |
max_height=2160 | |
aspect_ratio=$(bc -l <<< "$max_width / $max_height") | |
# Get image dimensions | |
dimensions=$(identify -ping -format "%w %h" "$input_image") | |
width=$(echo $dimensions | cut -d' ' -f1) | |
height=$(echo $dimensions | cut -d' ' -f2) | |
# Calculate number of parts | |
num_parts=$(((width + max_width - 1) / max_width)) | |
# Calculate part width | |
part_width=$((width / num_parts)) | |
part_height=$(bc <<< "scale=0; $part_width / $aspect_ratio / 1") | |
if [ $part_height -gt $max_height ]; then | |
part_height=$max_height | |
part_width=$(bc <<< "scale=0; $part_height * $aspect_ratio / 1") | |
fi | |
# Split the image | |
for ((i=0; i<num_parts; i++)); do | |
x_offset=$((i * part_width)) | |
convert "$input_image" -crop ${part_width}x${part_height}+${x_offset}+0 "${output_prefix}${i}.jpg" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If errors with image size being too much for
convert
: