Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
sort your digital photos by width, height or other exif-data
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
slick
Bodhisattva
Bodhisattva


Joined: 20 Apr 2003
Posts: 3495

PostPosted: Sat Mar 11, 2006 6:37 pm    Post subject: sort your digital photos by width, height or other exif-data Reply with quote

You have got a digital camera and take a lot of pictures or you collect otherwise a lot of pictures? This may help you.

This are examples how to sort, rename oder do other thinks with your pictures based on width, height or other exif-data. First we need media-gfx/jhead. The small binary jhead printout a lot of informations about an (jpeg) picture.

Examples:
Code:
# jhead 1.jpg
File name    : 1.jpg
File size    : 53555 bytes
File date    : 2004:10:19 11:46:11
Resolution   : 1200 x 798

Code:
# jhead 100_0640.jpg
File name    : 100_0640.jpg
File size    : 1004144 bytes
File date    : 2005:07:03 15:12:50
Camera make  : EASTMAN KODAK COMPANY
Camera model : KODAK CX7330 ZOOM DIGITAL CAMERA
Date/Time    : 2005:07:03 15:12:45
Resolution   : 1524 x 2032
Flash used   : No (auto)
Focal length :  5.6mm  (35mm equivalent: 37mm)
Exposure time: 0.0040 s  (1/250)
Aperture     : f/5.6
ISO equiv.   : 120
Whitebalance : Auto
Metering Mode: matrix
Exposure     : Action program (based towards fast shutter speed)

Now we can use this output in scripts.

I use find because I want process pictures in subdirectorys too.
Code:
find ./ -type f -iname '*.jpg' | while read file ; do
   resolution=`jhead "${file}" | grep ^Resolution | cut -d ":" -f 2`
   if  [ "$resolution" != "" ] ; then # check if really resolution found
      height=`echo $resolution | cut -d "x" -f 2 | sed -e "s/ //g"`
      width=`echo $resolution | cut -d "x" -f 1 | sed -e "s/ //g"`

      # here comes your lines to process the picture

   fi
done


For example you can use the following to ascertain the format of the picture
Code:
if  [ $width -gt $height ] ; then
   # landscape format
else
   # portrait format
fi

or you want to rename the picture? (width and height at first in the filename)
Code:
mv "${file}" "`dirname ${file}`/${width}x${height}_`basename ${file}`"

or you want to rename the picture? (width and height at last in the filename)
(work only at case-sensitive suffix, here *.jpg, not at *.JPG)
Code:
mv "${file}" "`dirname ${file}`/`basename ${file} .jpg`_${width}x${height}.jpg"

remove all pictures they are landscape format and width is smaller than 640 pixel
Code:
if  [ $width -gt $height ] && [ $width -lt 640 ] ; then
   rm "${file}"
fi


move all pictures from one day in several directorys based on (exif-) date:
Code:
find ./ -type f -iname '*.jpg' | while read file ; do
   date=`jhead "$file" | grep ^Date | cut -d ":" -f 2- | cut -d " " -f 2`
   if  [ "$date" != "" ] ; then # check if really date found
      YY=`echo $date | cut -d ":" -f 1`
      MM=`echo $date | cut -d ":" -f 2`
      DD=`echo $date | cut -d ":" -f 3`
      test -d "/destination/${YY}-${MM}-${DD}" || mkdir "/destination/${YY}-${MM}-${DD}"
      mv "${file}" "/destination/${YY}-${MM}-${DD}"
   fi
done


Sorry for my bad english, you can read this post in german too

If you think it is usefull please post an comment (or your script).


Last edited by slick on Mon Aug 14, 2006 7:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
neuronyk
n00b
n00b


Joined: 14 Aug 2006
Posts: 1

PostPosted: Mon Aug 14, 2006 6:23 pm    Post subject: Reply with quote

some people on the ubuntu chan where discussing to find a error on this script and finnaly they find that in the end you type a [ for a {
Code:

test -d "/destination/${YY}-${MM}-$[DD}" || mkdir "/destination/${YY}-${MM}-$[DD}"
      mv "${file}" "/destination/${YY}-${MM}-$[DD}"
 


instead of
Code:

test -d "/destination/${YY}-${MM}-$[DD}" || mkdir "/destination/${YY}-${MM}-$[b]{[/b]DD}"
      mv "${file}" "/destination/${YY}-${MM}-$[b]{[/b]DD}"


if it can help.... (i'm begining in scripting )
this is a nice script
Back to top
View user's profile Send private message
slick
Bodhisattva
Bodhisattva


Joined: 20 Apr 2003
Posts: 3495

PostPosted: Mon Aug 14, 2006 7:36 pm    Post subject: Reply with quote

neuronyk wrote:
some people on the ubuntu chan where discussing to find a error on this script and finnaly they find that in the end you type a [ for a {

Big thanks... I edit my post. :oops:
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum