For a test, I need to quickly create 1700 jpg-images (even blank) in a defined size 1000x706. I wonder if we could do this with a shell script or a program (like ImageMagick). I wish they called img_0.jpg, img_1.jpg

Someone knows a simple solution?


The following should work for your needs:

convert -size 1000x706 xc:white img_0.jpg || { printf '%s\n' 'Failed to create original image' ; exit 1 ; }
for (( _num = 1 ; _num < 1700 ; _num++ )); do
   cp img_0.jpg "img_${_num}.jpg" || { printf '%s\n' "Failed to copy to image img_${_num}.jpg" ; exit 2 ; }

ImageMagick creates the first image, and then it is copied to make up 1700 files. If ulimit doesn't restrict you from doing it (it probably will) and you have enough file descriptors, you could replace the loop with:

tee img_{1..1699}.jpg > /dev/null < img_0.jpg

You could also use the shorter idiom (with a larger memory requirement to store all of the numbers at once) for _num in {1..1699} in recent bash versions, but you don't specify which shells are available. (( is available in most shells (bash, ksh, and ash at least, not sure about others).

  • Thank you for your help. I try this in a few hours. Thank you for the idea =) I vote for your answer as soon as I have enough points
    – Raphaël
    Sep 22 '11 at 12:20

If you want a scriptable way to create lots of non-blank images, maybe consider: https://perlmaven.com/drawing-images-using-gd-simple

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.