Monday, December 5, 2011

Batch Convert Multipage CR2 to JPG

I landed up with a bunch of CR2 files (Canon Digital Raw Images from camera), which I needed to convert to JPG. On Ubuntu, I was able to view the CR2 format file using the installed Image Viewer and Gimp, after installing ufraw package.

However, the "convert" tool of ImageMagick was not able to convert to jpeg in a proper way - see the attached example converted images. This was due to the fact that the CR2 image has multiple pages and the "convert" tool is unable to understand this properly. (CR2 images with single page was successfully converted to jpg).

Gimp was able to open the CR2 file, but I had to specifically mention "Page1" in the "Import from Tiff"  dialog box. However, since I have to convert several CR2 files, manually opening them and converting was not an option. And I was also unable to figure out how to specify "Page1" in the gimp scripts (.scm files) or the Python-fu (pdb.file_load_tiff) scripts.

Finally, I was able to use the "convert" tool itself to convert to JPEG, but simply renaming the CR2 file as a TIFF file and using the same convert command like
convert renamed_cr2.tiff image.jpg
And that's it! It showed some errors about reading Tiff file (as it is not really a TIFF file) - but was able to successfully convert it.

Thursday, November 17, 2011

Killgrep - Kill a process by part of its name

We know the command kill that can kill a process by its id, and we know killall that can stop the processes by its full name. What if we need to kill a process by some part of its name and/or arguments. A simple killgrep script can do and here is how it is done:


# killgrep: Usage: killgrep 
# will kill the process running like "python"

echo $1

if [ -z "$1" ]; then
 echo "killgrep: "
 exit 1

PROC=`ps auxwww | grep "$1" | grep -v grep | wc -l`
if [ $PROC = "0" ]; then
 echo "killgrep: None killed"
 exit 1

PROC=`ps auxwww | grep "$1" | grep -v grep | perl -e '$_=<>; @u = split; print $u[1]' -`
if [ ! -z $PROC ]; then
 echo "killgrep: Stopping process $PROC"
 kill $PROC

Saturday, November 12, 2011

How to add a custom launcher in Ubuntu Unity Panels? (11.04+)

Prior to Ubuntu 11.04 (Natty Narhwal), you had Gnome Panel and it was easy to add a new custom launcher or an application to your Panel. But with Natty, by default, Ubuntu has the Unity interface which is very different from the classic Gnome Panel.

Now, you can easily create a "shortcut" on the Unity sidebar by opening the list of applications and then dragging a particular app onto the sidebar. But there is no obvious way to create a custom launcher - an application you have installed manually or a script that you have written, and get it placed on the sidebar. In my case, it was Thunderbird 8 which I just downloaded and placed it in /usr/local/thunderbird and I need to launch that instead of the regular packaged thunderbird.

Here is a simple method of how you can accomplish that:

  1. Right click on the Desktop. Click on "Create Launcher"
  2. Provide the name and path of the Launcher application and click OK to create the Launcher.
  3. Then just drag that launcher from the desktop to the sidebar panel! That's it!