Imagemagick File Padding Issue

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
jsells20

Imagemagick File Padding Issue

Post by jsells20 »

Hello, I'm having a problem figuring out the syntax for padding 10-99. Everything else in the program works fine so I want to focus in on just this part of the code. Below is a snippet of the code that I am having problems with. I appreciate all the help I can get. Thank you.

The script basically takes an image and adds the convert charcoal filter and spits out a sequence the user specifies. Problem is if the frame goes over 100...the padding is thrown off since 100 is set for greater than or equal to, where 10-99 needs to be specified to a limit before 100.

I seen a for loop where it uses {10..99} like so...
for i in {10..99} etc... but that will not work, it only prints 10 through 99. Please help...

Code: Select all

                ##no problem here

                if [ $count -lt 10 ]; then 
		convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.000$count.jpg
		fi


		##cant figure out the arithmatic here! 

	        if [ $count -ge 10 > 99 ]; then 
		convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.00$count.jpg
		fi


		##no problems here.

		if [ $count -ge 100 ] ; then
		convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.0$count.jpg
		fi
Last edited by jsells20 on 2009-07-21T15:10:35-07:00, edited 2 times in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Imagemagick File Padding Issue

Post by anthony »

I am not exactly following though I have an idea.

Can you give a breif examples of of the file names?

Are that
1 2 3 ... 10 11 .. 99 100 101 ...
or are they padded like
001 002 .... 099 100 101

You have two solutions in that case.

In shell use

Code: Select all

   for count in `seq %05d 999`
        convert ....  ${OUTDIR}${OUT}.$count.jpg
   done
which will result in 5 digit padded numbers being stored in the $count variable
You can have teh sheel pad a number

Code: Select all

  for count in {1,.999}
      padded=`printf  %05d $count`
        convert ....  ${OUTDIR}${OUT}.$padded.jpg
   done

Or you can get IM to do the padding

Code: Select all

    convert  .....    -scene %count filename_%05d.jpg
the %05d inserts the 5 digit number with zero padding

See IM Examples...
File Handling, Writing a Multi-Image Sequence
http://www.imagemagick.org/Usage/files/#write_seq

NOTE -scenes is used for input -scene is used for output!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jsells20

Post by jsells20 »

Hey thanks for that info. I actually got what I wanted using an if statement. The file name would be specified by $OUT by the user and the directory of OUT by $OUTDIR.

Code: Select all

	echo
	echo "2. Input what you would like to name your output files?"
	read OUT
	echo "the output name is now:" $OUT

Code: Select all

if [ $count -ge 10 ] && [ $count -le 99 ]; then
		convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.00$count.jpg
fi
Post Reply