Zend/PHP Conference - arrived to San Jose

I'm attending the zendcon this year. After 17 hours of flying (total) I got to San Jose but my luggage was lost. Joy! ... Lets hope that the rest of the week wouldn't go in the same path as the first day.



My PHP Cairo extension

Few monthes ago I started developing my first PHP extension. I decided to wrap libCairo which is a very cool 2d vector graphics API used by GNOME and other major projects. When I started working on it I did some research on the net to see that no one else had started doing the same thing. I came across Pierre, a very known and respected person in the PHP community, who told me that he started working on on a huge extension which is supposed to become a full replacement for the good'ol GD extension, based on libCairo. I offered to join him since I already knew the libCairo API pretty well but he refused to share any code, claiming that his extension will be released very soon. A few weeks later I decided to go on and continue my work on libCairo Extension for PHP because: a. I couldn't find anything else I liked and b. I though it might even be extreamly useful as a simple wrapper for libCairo, at least until Pierre's extension is ready.

Few days ago I was doing some reading and came across another Cairo wrapper extension for PHP in development. So it seems like a duplicate effort being wasted, however, my implementation uses OOP API (similar to the python PHP extension) and the other extension is implemented in a flat, C-Style API.

I don't know whether my extension is really needed or whether it will be accepted to PECL so for now I'll wait with it until I will know that it will be useful for someone or maybe try to submit it to PECL and see what happens.

0.0.3 is the first public version of my libCairo extension and the source code is available for download.

The extension doesn't cover the whole Cairo API and there is no documentation but the following code will give you an idea of what the API looks like:

$Surface = new
$ctx = new CairoContext($Surface);
$ctx->scale(256/1.0, 256/1.0);
$pat = new CairoPatternGradientLinear(0.0, 0.0, 0.0, 1.0);
$pat->addColorStopRGBA(1, 0, 0, 0, 1);
$pat->addColorStopRGBA(0, 1, 1, 1, 1);

$pat = new CairoPatternGradientRadial(0.45, 0.4, 0.1,
0.4, 0.4, 0.5);
$pat->addColorStopRGBA(0, 1, 1, 1, 1);
$pat->addColorStopRGBA(1, 0, 0, 0, 1);
$ctx->arc(0.5, 0.5, 0.3, 0, 2*3.14);

The output of this will be:

This snippet fully work in the current version and will produce the above picture.

Anyway, I don't know what will become of my extension but if there will be demand for it i'll continue coding.

It was a very educational experience and I believe that I'm ready to get my fingers even deeper into the PHP engine.