The White Room
Personal Website of Andrew McCombe-
Drawing an Arc in Imagick
Posted on June 19th, 2009 No commentsHere’s how to draw an arc using PHP Imagick
<?php $canvas = new Imagick(); $canvas->newImage(200, 200,new ImagickPixel("white"),'png'); $arc = new ImagickDraw(); $arc->setFillColor('red'); $arc->setStrokeColor('black'); $arc->setStrokeWidth(2); // x1,x2,y1,y2, start angle, end angle $arc->arc(30, 30, 160, 160, -70, 70); $canvas->drawImage($arc); $canvas->borderImage('black', 1, 1); header('content-type: image/png'); echo $canvas->getImage(); exit();
Produces:

-
Zend_Cache to cache an object
Posted on June 18th, 2009 No commentsHere’s how to cache an object using Zend_Cache:
<?php $cache_frontend_options = array( 'lifetime' => 3600, // cache lifetime of 1 hour 'automatic_serialization' => false ); $cache_backend_options = array( 'servers' => array( array('host' => 'localhost', 'port' => 11211, 'persistent' => true) ), 'compression' => false ); $cache = Zend_Cache::factory('Core', 'Memcached', $cache_frontend_options, $cache_backend_options); $key = 'myUniqueId-123'; $cache_object = $cache->load($key); if ($cache_object === false) { // not in cache $object = new myObject(); $cache->save(serialize($object), $key); } else { // in cache $object = unserialize($cache_object); }
Note: The reason that "automatic_serialization" is set to false and then I manually serialize and unserialize is that "automatic_serialization" didn’t work.
-
Turkish GP 2009
Posted on June 9th, 2009 No commentsQualifying was as expected with Brawn and Red Bull at the sharp end. However, it was Vettel that claimed the top spot from Button, Barrichello and Webber. McLaren continued their bad luck with Kovalainen 14th and Hamilton 16th. There was no ‘incident’s to cause their poor qualifying, just a basic lack of pace.
The published fuel weights showed that Vettel was the lightest of the four with Webber being very heavy. Strategies meant that two stops was to be the norm with three possible.
The race started well with Vettel taking the lead from Button and Webber. Barrichello had trouble with his gearbox and slipped down to 13th at the first corner, eventually losing 7th gear and retiring. At turn 9 on lap 1 Vettel had a moment and Button pounced to take the lead which he dominated for the rest of the race. Vettel’s expected change of strategy from a three stop to a two stop didn’t materialise which aided Webber to claim second spot on the podium with Vettel coming in third.
Vettel was visually frustrated with the Red Bull team on the podium and in the press conference and cited the three-stop strategy as the main reason he was behind Webber in the latter part of the Race.
Final Positons:
- J. Button (Brawn GP)
- M. Webber (Red Bull Racing)
- S. Vettel (Red Bull Racing)
-
Installing and using PHP ImageMagick (Imagick) Module
Posted on June 9th, 2009 No commentsInstallation
On an Ubuntu System:
sudo apt-get install imagemagick libmagick9-dev php5-imagick wget http://pecl.php.net/get/imagick-2.2.0.tgz tar xvfz imagick-2.2.0.tgz cd imagick-2.2.0 phpize && ./configure sudo make sudo make install sudo apache2ctl graceful
Example Usage:
<?php //Creating two Imagick object $first = new Imagick('tshirt.png'); $second = new Imagick('photo.jpg'); $first->compositeImage($second, Imagick::COMPOSITE_MULTIPLY, 220, 141); //new image is saved as final.jpg $first->setImageFormat(’jpg’); header(’content-type: image/jpeg’); echo $first->getImage(); ?>
-
Creative Zen and Rhythmbox
Posted on June 8th, 2009 No commentsI’ve never liked using Rhythmbox (Gnome’s default music player) as I found previous versions to be slow, buggy and crashed a lot. I’m trying to keep my system as close as possible to the default install so I’ve given Rythmbox one more change to impress.
I found the MTP plugin (in preferences > plugins) and enabled it, connected my Creative Zen 4GB and am happy to say it showed up and works.
Goodbye Gnomad2!
-
Using USB Audio with MPD in Ubuntu
Posted on May 18th, 2009 No commentsMPD is used as a music server in my office and Is running on an old Dell Latitude C400 Laptop. I have a Trust SC-5500p USB Soundcard plugged in and outputting sound to my amplifier.
To get Ubuntu (tested on Dapper, Edgy, Gutsy and Jaunty) working with the second sound card I needed to do the following:
1. Set the USB card as default:
zudo@music:~$ sudo asoundconf list
Please note that you are attempting to run asoundconf as a privileged superuser, which may have unintended consequences.
Names of available sound cards:
I82801CAICH3
Audio
zudo@music:~$ sudo asoundconf set-default-card Audio
Then reboot.
2. Set mpd to use the card.
sudo vim /etc/mpd.conf
Change the output to look like the following:
audio_output {
type "alsa"
name "USB Audio"
device "default:CARD=Audio" # optional
#format "44100:16:2" # optional
}Restart MPD and test:
sudo /etc/init.d/mpd restart -
Upload files with ncftpput
Posted on May 18th, 2009 No commentsncftp is a great set of command line ftp utilities. It supports a fully fledged FTP client as well as utilities for putting, fetching and batching files.
Here’s how to use ncftpput to upload a file:
ncftp -u username -p password www.hostname.com path/to/remote/file path/to/local/file


