»
S
I
D
E
B
A
R
«
Drawing an Arc in Imagick
Jun 19th, 2009 by Andrew McCombe

Here’s how to draw an arc using PHP Imagick

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:

imagick_draw_arcphp

Save as PDF

Zend_Cache to cache an object
Jun 18th, 2009 by Andrew McCombe

Here’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.

Installing and using PHP ImageMagick (Imagick) Module
Jun 9th, 2009 by Andrew McCombe

Installation

On an Ubuntu System:

sudo apt-get install imagemagick libmagick9-dev php5-imagick php5-dev
wget http://pecl.php.net/get/imagick-3.0.0b1.tgz
tar xvfz imagick-3.0.0b1.tgz
cd imagick-3.0.0b1
phpize && ./configure
sudo make
sudo make install
sudo apache2ctl graceful

Example Usage:

<?php
//Create two Imagick objects
$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 (and Banshee)
Jun 8th, 2009 by Andrew McCombe

I’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!

UPDATE 05/01/2010

I found rhythmbox to be far too unstable and tried Banshee (http://banshee-project.org/).  The Creative Zen works fantastically with the Banshee MTP plugin on Ubuntu 9.10 and Banshee 1.6 Beta 2 (1.5.1).

»  Substance: WordPress   »  Style: Ahren Ahimsa