It is currently Tue Dec 01, 2015 1:29 am

Recursive JPEGTRAN: Rotate your images with lossless results

All times are UTC - 6 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Thu Jul 23, 2009 10:57 pm   

Joined: Thu Jul 23, 2009 10:38 pm
Posts: 1
For those of you who are unaware of what jpegtran is, I suggest you press the link and read the Wikipedia article.

To install jpegtran, I used the following on Debian / Ubuntu:
# apt-get install libjpeg-progs

Remember, in order to execute the shell script, the file permissions should be altered:
# chmod a+x

The following is a code I have been writing to try to recursively rotate an entire directory of portrait images. Here are the details:

    Files to be rotated are moved in a directory ROTATE
    All final files are written to the parent directory of ROTATE
    File names are in the format DSC#####.JPG (no .jpg or .JPEG)
    File names are only 12 characters long

Here's the code. I've named it

picls=$(ls -1 /home/kp/Pictures/ROTATE)
while [ $numero -lt  257 ]; do
   picname=$(echo ${picls:$numero:12})
   `jpegtran -rotate 270 -outfile /home/kp/Pictures/$picname /home/kp/Pictures/ROTATE/$picname`
   numero=$(expr $numero + 13)

Now, unfortunately, I keep getting the following error from bash:
Empty input file
./ 9: Bad substitution

If anybody could provide insight on why bash is angry, then this shell script might be of some use!

 PostPosted: Fri Jul 24, 2009 12:35 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
First of all, that solution seems like a tricky one. But all roads lead to rome.

This is probably how I would've done it anyway.

for i in $in_path/*; do
   out_file=$(basename $i)
   jpegtran -rotate 270 -outfile $out_path/$out_file $i

usage: ./ /path/to/original/files /path/to/rotated/files

the first 4 lines shouldn't be that hard to decode.
Next up is the basename feature, it just convert an absolute path to just a filename.
And then your convert line

Best regards
Fredrik Eriksson

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group