Monday, July 30, 2007

Sort Digital Photos

Over the years I have collected thousands of digital photos from birthday parties, events etc. Having only a 64MB in my Sony Memory Stick it gets filled up very fast even at 600x480 resolution which is the lowest setting. Its become a habit dumping the pictures onto a new folder on my hard drive every now and then. After trying to sort the mess manually to try to organize the photos chronologically I managed to lose the one most important piece of information, the datestamp when the image was originally taken. Apparently when you do a copy in bash it does not preserve the datestamp instead it overwrites it with the one at which time the file was copied. Had I used the -a switch with copy I wouldn't be in this mess.
Fortunately there was still hope. I discovered that all jpegs included header information which contains the original datestamp as well as some other things that I wasn't interested in.

This lead me to write a simple bash script to extract the datestamp and sort the pictures chronologically in my album.

Here is the pseudo code:
*accept minimum 2 arguments the path_to_images path_to_write_location recursive_flag
*parse the date string from the jpeg
*loop thru all the images
*if write location does not exist create it
*construct a directory structure to place the images in the format Year/Month
*if format directory structure does not exists create it
*otherwise check if the file name exists in that directory so that we dont overwrite it
*if it does rename it before we copy it to the destination folder

Here is the entire code:

#Date: Feb 17 2007
#Author: Dejan Tolj
#License: GPL
#Bash script to arrange jpeg images chronologically
#Usefull when original picture taken date has not been preserved by
#accidentally coping without the -a option.

which identify &>/dev/null
if [ $? != "0" ];
echo -e "identify not found, please install ImageMagick.";
exit 0

# echo "Date stamp =$1"
# echo $1 | tr -d [:space:][:punct:] |touch -t /{} $2
date=`echo $1|cut -d: -f 1-4|tr -d [:space:][:punct:]` #2005:05:18 13:50:66

touch -t $date $2
# echo "Touch $date ->$2"


#parameters: jpg_path, write_location, recursive copy(optional)

if [ $# -lt "$PARAMSIZE" ];
echo "Enter the path to your jpeg files and the write location"
echo `basename $0` "[path] [write_location] -r"
#get first parameter
# echo $jpg_path
#get second parameter
#echo $write_location
#get third parameter if present else search in current folder only
if [ "$3" = "-r" ]; then
echo "$3"
recursive="-maxdepth 1"
echo "$recursive"

#Loop thru all jpegs and find the original date
for i in $( find $jpg_path $recursive -iname \*.jpg );
original_date=`identify -verbose $i |grep "Date Time Original"|awk '{print $4, $5}'`
#echo "OD=$original_date"

#Get Original year
original_year=`echo $original_date|cut -d: -f1`
#echo "OY=$original_year"

#Get Original month
original_month=`echo $original_date|cut -d: -f2`
#optionaly change date stamp

if [ ! -d "$write_location" ];
mkdir "$write_location"

filename=`basename $i` #strip the name of the image

if [ ! -d $mydir ];
# echo "Original month =$original_month"

mkdir -p $mydir
cp $i $mydir
#Optionally change the date stamp
#restoreDateStamp "$original_date" "$mydir/$filename"
#check name
if [ -f "$mydir/$filename" ];
echo "Renaming duplicate file"
if [ -f "$mydir/$filename"_$count ];
count=`ls $mydir/$filename_* |tail -1|cut -d_ -f2|tr -d [:alpha:][:punct:]`
cp $i "$mydir/$filename"_$count
cp $i $mydir
#restoreDateStamp "$original_date" "$mydir/$filename"

echo "$i -> $mydir";

exit 0

Saturday, July 28, 2007

Building Firefox

As a challenge I decided to build Firefox from source. The first thing I noticed is that unlike other Open Source software programs Firefox is not built using the standard configure, make, make install methods. They have a slightly different build script which I will explain in a moment.

My build process was completed on Ubuntu Dapper Drake, Pentium 4 2Ghz and 512MB RAM.

Here is the list of needed packages that you can download from Synaptic/apt-get in Ubuntu.
  • build-essential
  • libIDL-dev0.8
  • cvs
  • g++4.0
  • gcc4.0
  • make8.0
  • libgtk2.0-dev
Now that you have all the tools you need for building you need to check out the Mozilla source tree.

1. This code will checkout into ./mozilla from the Bon Echo branch. Go to that directory and the last command will checkout the browser project. This step may take a while depending on your internet speed.
$ cvs -d co -r
MOZILLA_1_8_BRANCH mozilla/
$ cd mozilla
$ make -f checkout MOZ_CO_PROJECT=browser
2. Before you can build you need to have a .mozconfig file in your ./mozilla directory. I have created this one which builds firefox with shared libraries, no optimization and I also enabled debugging. I also used gtk2 because I have version 0.8 of libIDL. By default the build will use gtk1. Create a new file called .mozconfig and copy the contents below. For a full list of acceptable flags you can see it here.
. $topsrcdir/browser/config/mozconfig
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/ff-static
mk_add_options MOZ_CO_PROJECT=browser
ac_add_options --enable-application=browser
ac_add_options --disable-static
ac_add_options --enable-shared
ac_add_options --disable-tests
ac_add_options --disable-optimize
ac_add_options --enable-debug
ac_add_options --enable-default-toolkit=gtk2
ac_add_options --disable-installer
3. Finally I fired the build command to compile firefox.
make -f build

Finally the build was complete

Saturday, July 14, 2007

Compiz fusion - compositing window manager

Last week I bought a new Video Card primarily for the benefit to make use of hardware acceleration on the desktop and as such run Compiz. Its a Nvidia GeForce FX5500, its several years old now but it plays nice with Linux and I have all the drivers to make it work. The driver installation was flawless on my latest Ubuntu gutsy, I then went on to install Compiz fusion. I pulled the latest development package for Compiz and the extra plugins which showcase some interesting effects on the desktop. Now comes the interesting part, the amount of features that you can change in compizconfig-settings-manager are astounding, you can customize just about anything to suite your liking. There are more than a dozen effects you can choose from for closing or opening a window, beam up, domino, fade and horizontal fold to name a few. You can add wobbly windows and my favorite 3D rotation. I increased the number of desktops under General Options>Desktop Size>Horizontal Virtual Size to 6, now when I go into 3D mode I see a hexagon with transparent view onto other desktops.

The only thing I was not able to get to work is the Group and Tab windows, but compiz is still in heavy development and I can't wait until they release a stable version.

One more thing I should mention is that Compiz is not just a toy with eye candy desktop and cool effects, many of the features actually make it a very productive environment to work in. I was a bit pessimistic when I first heard about it but once I had a chance to run it I loved it. Certainly the ability to have multiple desktops and to freely move windows across desktops as well as grouping windows would improve productivity and it feels like an organic way to do work on your desktop.

The long anticipated year of the Linux desktop has surprised everyone. Compiz may be the killer app on Linux desktop now but there have been many improvement on Gnome and KDE in terms of usability and adaption. No wonder Dell has finally decided to ship Ubuntu preinstalled on their laptops and PCs. I hope other hardware vendors take the same direction as Dell and allow Linux to prosper in the coming years. For now Microsoft and Apple don't even come close to what Linux has to offer on the desktop, what a great turn over because only few years ago everyone was saying that Linux would never go mainstream for having a poor interface. Way to prove these people wrong.