Wednesday, 15 February 2012

for loop - How to prevent from overwriting using imagemagick -



for loop - How to prevent from overwriting using imagemagick -

noobie question:

i seek batch convert files via imagemagick with

for in *.jpg; convert $i -colorspace grayness -rotate -90 -verbose out/%03d.jpg; done

it convert right way, overwrites output file on each loop instead of continuing progressiv number intended %03d.

input1.jpg=>out/000.jpg jpeg 2479x3508=>3508x2479 3508x2479+0+0 8-bit grayscale directclass 483kb 0.420u 0:00.339 input2.jpg=>out/000.jpg jpeg 2479x3508=>3508x2479 3508x2479+0+0 8-bit grayscale directclass 1.36mb 0.470u 0:00.390 input3.jpg=>out/000.jpg jpeg 2479x3508=>3508x2479 3508x2479+0+0 8-bit grayscale directclass 1.733mb 0.490u 0:00.410 input4.jpg=>out/000.jpg jpeg 2479x3508=>3508x2479 3508x2479+0+0 8-bit grayscale directclass 2.806mb 0.560u 0:00.480

you see, overwriting 000.jpg

i need hints go forth...

dearest lippe

class="lang-sh prettyprint-override"># define variable increment counter=0 # iterate on images image in *.jpg; # convert number `1' pretty format `001' printf -v pretty_counter "%03d" $counter # convert image convert $image -colorspace grayness -rotate -90 -verbose out/$pretty_counter.jpg # increment counter counter=$(( $counter + 1 )) done

or

class="lang-sh prettyprint-override">convert *.jpg -colorspace grayness -rotate -90 -verbose out/%03d.jpg explanation

imagemagick's escape sequence references image stack. invoking convert command within for loop, 1 image exist in stack, , file out/000.jpg generated. solution utilize bash generate output filename, or give convert files @ once.

for-loop imagemagick

No comments:

Post a Comment