Page 1 of 1

converting a directory of TIF to JPG

Posted: 2017-04-26T07:23:54-07:00
by flieckster
Hi all, i'm super noob at IM, and i'm just trying to convert a directory of images.

Code: Select all

cd /Users/flieckb/Desktop/from 
list=`ls *.tif`
echo "$list"
for img in $list; do
convert "$img" jpg "/Users/flieckb/Desktop/to/$img"
done
The above code simply copys the TIFF's to the 2nd directory without actually converting to JPG. what am I doing wrong?

I tired this also.

Code: Select all

cd /Users/flieckb/Desktop/from 
list=`ls *.tif`
echo "$list"
for img in $list; do
mogrify -path /Users/flieckb/Desktop/to/ -format jpg
done

Re: converting a directory of TIF to JPG

Posted: 2017-04-26T07:35:24-07:00
by snibgo
Both of your IM commands are wrong. I suggest you experiment, with just one file, to understand the commands.

Code: Select all

convert "abc.tif" "/Users/flieckb/Desktop/to/abc.jpg"
This^ reads a tif file, and writes it as a jpg to the directory.

Code: Select all

mogrify -path /Users/flieckb/Desktop/to/ -format jpg "abc.tif"
This^ does the same.

Code: Select all

mogrify -path /Users/flieckb/Desktop/to/ -format jpg "*.tif"
This^ does the same, for all *.tif.

Re: converting a directory of TIF to JPG

Posted: 2017-04-26T07:48:25-07:00
by flieckster
ahh thank you that makes sense. i could convert one file, but it it would change the name to "*.jpg" and stop. the last bit of code seems to work great. i'll have to pick that apart more and play with it. thank you very much.

Re: converting a directory of TIF to JPG

Posted: 2017-04-26T08:16:59-07:00
by snibgo
Yes, "convert" needs an input filename and output filename. The output filename would need to end with ".jpg".

"convert" usually operates on one file per invocation, so needs to be in a shell loop.

For this job, "mogrify" is the obvious tool. It needs an input filename (often with wildcard). IM will build each output filename from the path, the name of the input file, and the format.

"mogrify" can process one file per invocation, inside a shell loop. Or you can use wildcards, so there is no need for a shell loop.

Re: converting a directory of TIF to JPG

Posted: 2017-04-26T09:17:41-07:00
by fmw42

Re: converting a directory of TIF to JPG

Posted: 2017-08-14T00:49:05-07:00
by merkthere
Install imagemagick $ sudo apt-get install imagemagick

It's simplest usage is: $ convert File.tif File.jpg

It is smart and goes by your file extension.

Now, for doing batch conversions, we shall use a loop.

cd into the directory where your tif files are.

then: $ for f in *.tif; do echo "Converting $f"; convert "$f" "$(basename "$f" .tif).jpg"; done