Pictures Programming

Bash script to convert pictures using ImageMagick

If you have ImageMagick installed, here’s a simple bash script that allows you to convert a whole lotta pictures in a folder to a different size. Just modify the folder names to reflect where your photos are stored :

#!/usr/bin/env bash

# This program converts all the pictures that are stored in the folder To-Process to half their size
# and names the resulting photos the same but with -r added to it.
# For this, it uses the ImageMagick programs, so these need to be installed ! Either download a binary version or
# compile them yourself (but you need libjpg at a minimum compiled/installed as well.)
# The resulting photos can be imported in iPhoto.

username = <your username here>

# This processes all JPG pics that are in the folder
for photo in /Users/$username/Pictures/To-Process/*.JPG
echo “Converting $photo”
# Using the IM convert program
convert -resize 50% $photo ${photo%%.*}-r.jpg

mv /Users/$username/Pictures/To-Process/*-r.jpg /Users/$username/Pictures/Processed

Took me a hour or two to go back reading the bash manuals and tutorials and get it working right. As for ImageMagick, you can either download binaries for OS X (of for windows for that matter) or compile your own. Remember though that you also need to have libjpeg installed as IM depends on this on compile time.

Yes, of course you can do this with other programs, but this is all part of my plan for getting a workflow up and running to process and store my photos. More on this later.

Apple Programming

Mac Automator

I discovered a new function in the mac ‘automater‘ – the graphical GUI tool that allows you to drag-n-drop parts to make a batch program.

You can actually save a created automator script as a plugin – the most useful in this case would be an iCal plugin. This allows you for example to create a script that can be launched at certain times (but your computer needs to be awake for it work, though).

Very cool – I used to do this via Cronnix, but this is better.

There’s actually heaps and heaps of automator actions that are becoming available all the time. It’s great ! You can create an automator script that will

  • import your photos from your camera
  • rename and resize them (if you have the correct programs installed)
  • and will upload them to your website
  • and create a backup .dmg file, ready to be archived on cd or dvd

I loooooooove my mac !

Blog News Programming

Now Reading plugin conflict (MySql Error)

I have been trying to implement the “Now Reading” plugin from Roblog as I thought it was a great way to keep track of what books I read and at what date.

But I couldn’t get it to work. It kept crashing with a MySql error whenever I wanted to add a book to the list in the admin interface. Despite several comments in the blog entry by me and others who had the same problem, the author of the plugin did not react to propose a solution.
One enterprising soul who had the same problem, found the answer however, and I’ve since corrected it and activated the plug in (although it won’t show up on my homepage as yet). I’m now documenting the fix here as well.

The problem is that Now Reading re-uses a WordPress variable called “query” without reinitializing it. Normally this does not cause any problems, but if you have a plug in (like for example weathericon) that query variable is already used, and thus contains data.
Solution : in the Now reading plugin, modify the add.php file and add a line all the way in the beginning :


This resets the variable to “empty” and thus the result returned to the browser will be valid.

Links Pocketpc Programming Websites Caught !

How Windows Mobile 5 gets developed

The Windows Mobile Team Blog is a great resource, I’ve found it very useful on occasion to get a glimpse into the developers mind.
In his “I’m just a feature” article, Mike Calligero explains what it takes for a feature request to get into a new Windows Mobile 5 build.

[If you are interested in knowing more about software development, head over to Joels site for lots of great, well-written articles on what a programmer needs to do to get a program released and get it stable]
It’s an eye-opener for those users who have never known or realised what it takes for an improvement or feature request to get through the build proces of a major application that is released in 25 languages and to millions of users.

Blog News Programming

Python and cx_Oracle

Recently I have taken over the maintenance of an application at work that was written very quickly and, to be honest, rather badly. A department needed the app badly.

I hasten to add that it is bad because it was done so quickly. Plus the person who wrote it is not used to writing EndUser applications.

It uses an ODBC connection to an Oracle db, plus an Access db to connect, plus Excel to show the final info in. Inside the MSAccess db are 4 different queries all building on each other, each one paring information away from the previous query using left joins. To refresh the data the user must do a manual refresh and each time input the password.

Adding a component to monitor to it involves updating the Access db (easy) and then recreating at least two pivot tables as well as adding the component to other excel tabs and fields, easely 15 minutes of work. And the problem is that this is probably only going to get more critical…

So I’ve started to investigate if I could do something about this, like rewriting it in Python and then compiling it in an end-user application using py2exe. I’ve rescued all the sql queries and table connections from MS Access.
One thing is very clear : SQL queries made from Access suck ! They are like the html docs that MS Word makes – full of useless cruft everywhere

I am now trying to remake the program using Python 2.4.2, cx_Oracle for the Oracle connectivity and PySQLite. So far I’ve managed to connect to the database and execute the first query.

Note to self :

  • when debugging an SQL query, cx_Oracle or even Oracle itself, who knows, does the query evaluation backwards. It will start evaluating your SQL expression from the back. Usefull to know when you get an error, you need to look from back to front !
  • also, you don’t need a ; at the end of your SQL query for cx_Oracle. In SQLite you do. In Oracle you do not. Two days, mate, two days before I found this.

Next up : trying to get the Left Join to work as well a Tkinter window setup to show the user something. Luckely I’ve got a knowledgeable sql guy not far from me… and I am not even sure that is the way to go, just emulating what has been done before…

Blog News Programming PSP

Python on the PSP

I have a programming urge coming over me. They come and go. Usually they leave when I realise (once again) how much hard work has to go into something before it is somewhat playable or workable. However, lately at work I wrote some bash and python scripts that really worked and had some useful output !

Sooo, what better to look at programming than trying to write the latest app or game for my psp that millions will download and enjoy so much they will elevate me to programmer god ?

I know.
I’m just kidding.

But the urge to go forth and create something is still there.

There are some tutorials floating around on the web on how to start programming your psp using the psp sdk kit (you need either cygwin or linux). I looked them over, but didn’t like it. I don’t have enough time to start learning C or C++ again. Plus pointers still make me shudder.

So I looked to other possibilities, like the luaplayer, which lets you write lua programs that ‘play’ on your psp.

Nah, don’t have time to learn lua either. So what can I still do to scratch that (psp) programming urge ? PSP Basic ? Doesn’t exist (yet). Python ? Hey ! Look what Google found !

I found a site by a french guy who has already ported python to the psp, including some standard modules. He also added a tutorial to it that is really good and explains a lot.

Also, his blog makes for some strange readings !

If only… I had more time. Like I used to have, back when I was 20+ and still living at home. Not now when I have two kids to take care of and a full life. I can look at this code, even install it on my psp maybe and test it, but I don’t have the urge to continue and develop stuff using it.

Gah. Guess my urge to program is over.