Splitting Batch of 100 images into 5 (500) retain name +0-4

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
leafpressed
Posts: 4
Joined: 2014-09-28T06:20:26-07:00
Authentication code: 6789

Splitting Batch of 100 images into 5 (500) retain name +0-4

Post by leafpressed »

How do I split a folder of about 100 images into 5 each, the above image would be split and renamed like 18_14+4_97_0(,1,2,3,4)? Input images are 4500 pixels wide, dividing each image into 5x900 pixel wide images... (516 pixels tall...)

Hi, I figured out this on my own before, but I lost my notes :( It seems that there are multiple ways of doing things in ImageMagic :) ImageMagick is a gateway drug for self-taught programming :D

I am downloading weekly ocean tidal graphs for a specific tidal station from a dependable online source, with the goal of cropping, resizing to scale each image (due to the scale of the graph varying from 18 feet to 10 feet in size over the same sizedimage, applying artful filters for less -graph-ey chopy graph line, then splitting each image into 5. I delete days 6 and 7 from the image because in that portion of the image there is a key of the same color as the graph line that sometimes intersects with it and would be nigh impossible to remove from the affected images when I am operating on the whole folder. So not weeks, but groups of 5 days, about 100 of them, representing 70 weeks.

When using convert, *_%d.gif is not working, naming the files *_0,1,2,3,4 and when using mogrify, -crop with -repage and -adjoin is not working, as -adjoin does not seem to be compatible.

mogrify *.gif -crop 5x1@ +repage +adjoin *_%d.gif
OUTCOME mogrify.im6: unrecognized option `+adjoin' @ error/mogrify.c/MogrifyImageCommand/3918.


I found a simple bash script from these same forums, but I do not know how to modify it to retain the original name of each file with an added _0,1,2,3,4 at the end of the file name.

for f in *.gif do convert $f -crop 5x1@ split/$f_%.gif
OUTCOME: bash: syntax error near unexpected token `for'


But I was just Frankensteining commands, I do not know anything really about bash scripts, scripts in general, and enumerated and naming conventions that use *, $, %, other than my previous experience with * and mogrify I think it was... (I sucessfully transformed whole folders of images, I just don't remember if i used convert or mogrify)

The naming outcome desired is like the folllowing: 18_14+4_97 means: 18 feet of tidal graph 14 feet positive, 4 negative holds 13.something and -3.something tidal data graph, 97th group of 5 images, for about week 70.

SO...

How do I split a folder of about 100 images into 5 each, the above image would be split and renamed like 18_14+4_97_0(,1,2,3,4)? Input images are 4500 pixels wide, dividing each image into 5x900 pixel wide images... (516 pixels tall...)

PS if I reorder the imagenames, which would be easy for me to do for this batch of 100, but I will be doing many more batches if I name the images 97_18_14+4, how would I split them and rename them like 97_0(,1,2,3,4)_18_14+4.gif so that all the images would be in order and essentially by the day?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Splitting Batch of 100 images into 5 (500) retain name +

Post by fmw42 »

try this. Assume your images are in test1 and you have an empty folder test2 in which to put the results. Both are on the desktop for this example. You can change the locations as desired.

Code: Select all

cd desktop/test1
list=`ls | grep ".gif"`
for img in $list; do
name=`convert $img -format "%t" info:`
convert $img -crop 5x1@ ../test2/${name}_%d.gif
done
leafpressed
Posts: 4
Joined: 2014-09-28T06:20:26-07:00
Authentication code: 6789

Re: Splitting Batch of 100 images into 5 (500) retain name +

Post by leafpressed »

I had problems logging in for a bit to report on my progress, but thankyou this works after I add /home/username before /desktop (for the newbiest of newbs...) to the arguments that get copied and pasted into Terminal.
Post Reply