Michael Maclean

Cairo talk feedback from DPC10

I noted a couple of comments after my talk on Cairo at DPC 10 yesterday, so I thought I’d respond to them here to clear up what’s going on. It’s always good to get some feedback about something I’ve been working on so I’d like to reply and keep the conversation going if I can.

First off, someone mentioned that the wrapper seems a bit beta and incomplete - and yes, that is true. The 0.2.0 release, which is the latest as I wrote this, is still marked as beta. The aim of me coming and talking about it is to try and get some more people interested in using it, so we can get somemore information from real users about what works and what doesn’t. I probably didn’t help by mentioning that there are some features that we intend to implement that aren’t there yet, which I’ll list:

  • Support for reading and writing images that aren’t PNGs The developers of the core Cairo API are not really interested in handling all the various graphics formats that exist, so they decided to implement one and one only which is useful for getting data in and out. This is the functionality that we use at present. We (the developers of the wrapper) would like to fix that and handle JPEG, GIF, TIFF, and whatever new format is cool this week, but we’re not quite sure how to go about that yet. We could recycle the code used by GD or use ImageMagick or GraphicsMagick, but those would introduce dependencies that people might not have available. Once we work out a decent solution here, it will be put in.
  • Support for hyperlinks in PDFs and SVGs Again, this is something we’d quite like but it’s not supported in the underlying library yet. There have been rumours about adding an API to do this, but there hasn’t been a concensus about what’s a good way to go about it. It’s something I’d quite like to help fix, so I’ve been learning how Cairo itself is put together with the intention to add the support.

The other comments I saw suggested that the API is a bit fiddly, which I can’t deny. It’s not quite as simple to set up and get running as some of the other libraries in PHP already. This is nearly intentional - we’re wrapping the underlying Cairo API as closely as we can, because we don’t want to diverge too far from how other languages with Cairo wrappers work, so that developers who may be familiar with those already know roughly what is going on. It’s for this reason that, for example, the API uses floating-point values from 0 to 1 to define the intensity of colours, rather than an integer value from 0-255 which most people are probably used to. This is because Cairo is designed not to make any assumptions about the surface you’re going to be drawing to - some day we might get 16-bits-per-channel surfaces, and using float values means that we don’t need to change the API or the values we’re passing in to allow us to write to them. It’ll just carry on working as it did before, just with better colour resolution.

However, if anyone has any ideas for how we could make things simpler, then we’d love to hear about it &emdash; drop us a line on the PECL developers mailing list (which you can find on the PECL mailing lists page), or find us on IRC on #php.pecl on EFnet.

There are a couple of things that I have worked on which sit on top of the Cairo extension, which can do some interesting things. If you’re still at DPC I’ll be demoing a couple of them on the uncon track at 2pm. It’s only a 15 minute talk, so it shouldn’t be too boring…!