Mludd's Short URL Application

Posted by mikael on 2012-08-16 21:15, section: Software

This summer I created a little webapp I call MSUA or Mludd's Short URL Application. To sum it up, it's a PHP web application for URL shortening that converts URLs into a six or seven character Base62 hash. The license is GPLv3.

You can try it out, download the source and read more about it at its own site.

Color space class for PHP

Posted by mikael on 2011-11-24 15:19, section: Software

I've thrown together a neat little color space manipulation class for PHP that I call ColorCreator. Admittedly it appears there's a fairly nasty bug in it at the moment and it currently only handles HSL and RGB values but I'm working on it.

Feel free to try it out, just avoid the rgbToHSL function for now…

Analog clock images with Bash and ImageMagick

Posted by mikael on 2011-07-17 16:39, section: Hacks

A little while back I decided to try creating a script that would generate PNGs of an analog clock so I could run the script using cron and display the images with Geektool, this is the result.

First of all we need three images to assemble into the final clock. Below are the ones I created and used, consider them free to use if you want to.

Background for the clock Hour arm for the clock Minute arm for the clock

Next, put the three images in a directory and create the following script in the directory.

#!/usr/bin/env bash

# Path to ImageMagick convert program
conv="/usr/local/bin/convert -quiet"

# IMPORTANT: Set this to the path where the images and the script reside.

# Time in hours
hourtime=`date "+%H"`
if [ "$hourtime" -gt "12" ]
        hourtime=`expr $hourtime - 12`
        # now $hourtime = hours since 12

# Time in minutes
minutetime=`date "+%M"`

# 1 find angle of hour arm
hourasminutes=`expr $hourtime \* 60`
minutessincetwelve=`expr $hourasminutes + $minutetime`
hourangle=`expr $minutessincetwelve / 2`

# 2 find angle of minute arm
minuteangle=`expr $minutetime \* 6`

# 3 combine bg and hour arm
$conv ${basedir}hour_1000x1000.png -virtual-pixel transparent \
+distort SRT "500,500 1.0 $hourangle 500,500" \
-trim ${basedir}bg_1000x1000.png +swap -background none \
-layers merge +repage ${basedir}tmp.png

# 4 combine result of 3 with minute arm
$conv ${basedir}minute_1000x1000.png -virtual-pixel transparent \
+distort SRT "500,500 1.0 $minuteangle 500,500" \
-trim ${basedir}tmp.png +swap -background none \
-layers merge +repage ${basedir}tmpout.png

# 5 add drop shadow
$conv ${basedir}tmpout.png -virtual-pixel transparent \
-background none \( +clone -background none -shadow 30x10+0+0 \) \
+swap -layers merge +repage ${basedir}out.png

If you run this script you should get an image called out.png that looks a lot like the one below (and two images called tmp.png and tmpout.png but if you can't figure out how to modify the script to get rid of them you probably shouldn't be running random scripts from the net anyway). The out.png image is also 40 pixels higher and wider than the source images, if you skip the drop shadow it will be the same size as the source images.

I hope this was useful for someone out there.

Final result

Clock screen saver with Quartz Composer

Posted by mikael on 2011-05-31 18:55, section: Software

I went looking for a good clock screen saver for Mac OS X today, found a few but figured I could probably create my own. After considering what tool to use I decided I'd give Quartz Composer a go. Turns out it was both easy and hard.

Creating the basic clock was not very hard, getting it to not flicker was a bit harder (it appears that this is a bug with how Quartz Composer files are rendered as screensavers).

Quartz Composer overview

What I ended up doing was creating an Interpolation patch that feeds into the Hue input of an HSL Color patch with its Luminosity value set to 0.001 which in turn acts as the background for the clock text, this way it appears like the screen is in constant need of being redrawn even when it is not, thus avoiding the flicker issue I had.

I went for a very large font (Helvetica Neue Bold covering almost the entire screen) but this can be easily changed by opening the .qtz file with Quartz Composer and editing the Image With String patch.


To install it all you have to do is copy/move the .qtz file to ~/Library/Screen Savers/. It should now show up in your list of installed screen savers.

Download here

Comments via Disqus

Posted by mikael on 2011-05-28 15:49, section: Index

Well, I finally decided to not construct my own system for user comments and just added DISQUS comments to all blog posts instead.

I also removed the CSS sprite article because it was kind of low quality (I threw it together pretty quickly). There are still plenty of articles about CSS sprites online though.

Working on a site update

Posted by on 2011-04-23 14:32, section: Index

Well, I've been hard at work trying to update the site, so far little of this is visible to visitors since I'm, obviously, doing it in a lab environment.

The changes will include both a new design as well as little improvements such as code highlighting for code samples posted. I've also been cleaning a lot of cruft out of the code for the website.