Register
It is currently Wed Apr 16, 2014 2:14 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:
Code:
# apt-get install libjpeg-progs


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


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 Rjpegtran.sh:

Code:
#!/bin/sh
numero=0
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)
done


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


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


Top
 Profile  
 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.
Code:
#!/bin/bash
in_path=$1
out_path=$2

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

usage: ./script.sh /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


Top
 Profile  
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 2 guests


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
© 2003 - 2011 USA LINUX USERS GROUP