Home > other >  Only cropping/appending a subset of images from an image sequence
Only cropping/appending a subset of images from an image sequence

Time:10-20

I have a numbered image sequence that I need to crop and append, but only certain frame ranges.

Example, sequence of 100 images named as follows:

frame001.jpg
frame002.jpg
frame003.jpg
...

Sometimes might only need to crop and append images 20-30, or other time, 5-75.

How can I specify a range? Simply outputting to a PNG.

CodePudding user response:

For examle, if you want to pick the jpg files in the range of 20-30 and generate a png file appending them, would you please try:

#!/bin/bash

declare -a input                                        # an array to store jpg filenames
for i in $(seq 20 30); do                               # loop between 20 and 30
    input =( "$(printf "framed.jpg" "$i")" )         # append the filename one by one to the array
done
echo convert -append "${input[@]}" "output.png"         # generate a png file appending the files

If the output command looks good, drop echo.

If you are unsure how to run a bash script and prefer a one-liner, please try instead:

declare -a input; for i in $(seq 20 30); do input =( "$(printf "framed.jpg" "$i")" ); done; echo convert -append "${input[@]}" "output.png"

[Edit]
If you want to crop the images with e.g. 720x480 300 200, then please try:

#!/bin/bash

declare -a input
for i in $(seq 20 30); do
    input =( "$(printf "framed.jpg" "$i")" )
done
convert "${input[@]}" -crop 720x480 300 200 -append "output.png"

The order of options and filenames doesn't matter here, but I have followed the modern style of ImageMagick usage to place the input filenames first.

  • Related