Archive for the ‘General’ Category

Identifying portrait/landscape in a set of images, with ImageMagick and BASH

I haven’t written much BASH of late, so was a bit rusty. The goal? A script that would go through a directory of JPGs, find those that are portrait shots, and place them in an appropriate folder. Do so similarly for landscapes.

Use cases? Those new digital photo frames. Buy two, and have many images scroll by, eh?

What’s been done?
Making use of ImageMagick’s identify is what needs to be done. You’ll be using the -format option, which normally takes a type or string. A full list of what options are available for -format are available.

The choice is to use -format '%[exif:orientation]'. The output of identify -format '%[exif:orientation]' is either:

  • 1 – portrait
  • 6 – landscape
  • 8 – portrait (the way I normally shoot, with the battery grip)

I’ve not seen much documentation about the above, so it seems like these values come from trial and error… They apply for Canon cameras that have EXIF orientation details. I’d be interested to hear from others what values they’re getting (or getting pointed to some documentation).

The shell script?

#!/bin/sh

mkdir portrait
mkdir landscape

for i in *.jpg;
	do
	type=$(/opt/local/bin/identify -format '%[exif:orientation]' $i)
case $type in
	1)
	mv $i portrait;;
	6)
	mv $i landscape;;
	8)
	mv $i portrait;;
esac
done

Other bits of BASH?
If you do: type=$(/opt/local/bin/identify -format '%[exif:orientation]' $i) , you can grab the value from the command (1, 6, 8) and manipulate it. Check by doing echo $type.

If you’re after getting the return value from a command (i.e. 0 for success, 127 for error, and so on), you can do echo rv: $?.

All in all, remember to read the BashFAQ. Tests and Conditionals was also essential to my reading.

ImageMagick rocks nonetheless. I’ve used it before to resize, append and much more… I’m thinking that maybe its time to read The Definitive Guide to ImageMagick, written by Mikal.

Secure travelling with ipfw on OS X?

Dear (mac/bsd) Lazyweb,

Any idea how I can do the following, on Mac OS X?

iptables -t nat -A PREROUTING -p tcp -d my.pop.server —dport 110 -j DNAT —to-destination 127.0.0.1:1235
iptables -t nat -A OUTPUT -p tcp -d my.pop.server —dport 110 -j DNAT —to-destination 127.0.0.1:1235

Does ipfw(8) work in OS X? What magic will I have to use for this to work? All I really want is for my.pop.server:110 to point to localhost:1235, so if the SSH tunnel isn’t up, I can’t POP my mail. I wrote about this in Secure travelling tips with iptables and SSH port forwarding, as that’s what I do on Linux.

Why do I ask? I’m thinking that my personal laptop (currently a Dell Inspiron 640m running Linux) might actually be replaced with a MacBook Air in the near future (lighter, easier to carry, etc.). Oh, if you have comments about the Air, don’t hesitate to tell them to me as well.

Students: OpenSolaris, NetBeans blogging contest

As some of you would have recently noticed, I’ve started playing around (I can’t really say using, seeing that its still not a daily basis kind of thing for me yet) with OpenSolaris and NetBeans. Now, Sun is encouraging students to use, review, and blog about these two great products – check out the student reviews contests.

If you’ve not tried OpenSolaris 2008.05, you should probably give it a twirl. Sure, I’ve not installed it on bare metal hardware yet (I’ve been travelling so much, I’m not anywhere near machines), but it works fine inside VirtualBox. NetBeans is great if you’re writing Java, Ruby, PHP, and are connecting to a database – Connector/J for MySQL is shipped with it. If you were trying it out, take a look at the NetBeans+GlassFish+MySQL bundle.

So, students out there, take a look at the Student Reviews Contest. You have till June 6, 2008. There’s your chance to win anywhere between $100-$250 (USD?), which really means a lot of beer ;)

(and here’s hoping we run something similar when MySQL 5.1 is GA… we used to run bug finding contests where we used to give away iPod Nano’s, though I think Visa Debit Card’s are so much more useful than iPod’s…)

Maxis on the anti-SMS-spam bandwagon

It was reported recently that Maxis (my current mobile provider of choice), will offer an anti-spam service for cellphones.

Once you get MessagePlus, which costs RM1 per month, you can start blocking spam. Where do I get most of my spam from? Maxis information services!

So, while this magical service is the first in the world, is this just because Malaysia lacks an extension to the Do Not Call Register?

MessagePlus also includes an auto-reply feature for SMS messages. Think of this like vacation mail, in traditional e-mail. Vacation mail that costs money – you’re charged on a per SMS basis, ranging from between 5-15 sen per message.

It seems Maxis has a new business development manager, Nikolai Dobberstein. And the idea of sending spam, and charging folk to stop receiving the spam, seems like its just gold! Excellent idea for business development, I’m sure.

Me? I’ll live with the spam. And when mobile number portability shows up (find link), I might move to another sensible provider.

A useful statistic? Malaysia’s SMS use is ranked at sixth in the world, for total SMS volume.

Changes in the blog

Its worth noting some website changes. First, I dropped Skribit. The widget has been sitting there unused for weeks, so I’m thinking that’s software that no one, besides its founders use. “Is Skribit proving useful?” is the question they ask – no.

Next up, I’ve stopped using Technorati tags, and have decided to use WordPress tags. I’ll still be using categories, as well as tags to complement the categories. Why? WordPress has the feature… Technorati still gets updates/pings from my blog, and creates its own “tags” (largely from what I can see, from ways I categorise my post) that it sees my blog represents.

Besides, now I can add tags for relevant events, and RSS feeds can be generated from it. Good for people just wanting to follow notes from a certain event, and aggregations of the specific feed for said events.

Of cleaning keyboards and virii

In a tiny fit of paranoia, as the Norovirus has decided to pay a visit to the Moscone this week, I decided that I needed to clean my keyboard on the Macbook.

I’ve already been following best practices of washing ones hands before eating with them (say bread at a restaurant even). You learn this stuff as a kid, but somewhere in-between growing up, and finding a girlfriend, you decide to share over cleanliness. Anyway, the habit has been back for a while. This largely after looking at toilets in a many a men’s wash room, where I notice that a lot tend to not wash their hands!

Anyway, to the point. Keyboard Cleaner. Tiny application that locks everything up, allows you to clean your keyboard and trackpad, and then with the magic Command+Q only will the application exit. Its small, but it serves a useful purpose.


i