The force is with me little one…

I have written over the last two days RB bindings for libgd, in the continous search for a replacement to the Picture object, which is missing in console apps. As long as the promised-and-long-forgotten SwordFish project won’t be released, there’ll be little need, I think, or more accurately little clamoring for a Picture object – but once people start writing web apps in RB, you bet your ass they’ll want to produce images on the fly, like everybody else…

So. GD’s one option I had been thinking about – while still thinking I could build my own. And fPic works well enough, albeit with quirks. And it covers lots of ground – including PDFs, thanks to CoreGraphics. But it’s not very portable – my attempts to make it work on Linux, sans PDF and vImage.framework, failed so far. Since gd works on all platforms, I thought I could try it out. And sure enough it was easy to write bindings to the library, with very few quirks – I am having problems with saving to wbmp format, but who cares about that format anyway? :-)

One format that’s missing in GD is TIFF – which fPic handles very well, na na na – so I re-read fPics Tiff code [a wrapper to libtiff really] and converted that to RB. Which means I ended up writing bindings to libgd *and* libtiff, oh so much fun! It only reads TIFF files for the moment, as I haven’t worked out how to get access to the int **tpixels array from RB, in order to save as Tiff. Might have to write a small dylib to go with it – or use fPic’s very own manip.dylib! :-)

Like in fPic, when using freetype2 to draw text, one has to pass the path to a .ttf font file. It’s not exactly user-friendly, so I am trying to find a way to provide for a better interface into that. Maybe a Font class that’ll take care of the nitty gritty work. I found a good code sample to retrieve the name of a ttf font. Could be useful…

4 Responses to “The force is with me little one…”

  1. jdiwnab Says:

    Would this work better than the built in picture stuff in GUI apps?

  2. dda Says:

    Heya jdi. I dunno about “better” – you’d have to define that. But first in console apps we can now manipulate pictures [I’ve been able to do so with my fPic class/dylib, but anyhow] and that’s a big plus. Then, there’s a lot of gd stuff available on the net, and converting those scripts to RB would be a snap; I am even thinking of writing a C/PHP to RB converter for gd code. One good thing is that it doesn’t require QuickTime to handle Jpeg/Png/Gif/Tiff – it’s all in there, except you need lib[jpeg|png|gif|tiff] anyway – but that’s often present by default on *nix boxen.

    I haven’t timed libgd4rb vs the Picture object – I am curious though – but again, performance is not – yet – the issue, as the goal is to be able to manipulate graphics in RB console apps. Saving as .PNG is kinda slow – not my fault señor – but it beats saving to .BMP/.PCT and .JPEG only, as is available with the Picture object. Saving as .GIF is also available, although I haven’t tackled the issue of animated graphics. The GD library was originally geared towards GIF images – the G in GD stands for Gif after all – and there’s a shitload of Gif functions in there. I’d like to be able to save as Tiff, but I am not sure there’s that big of a big need for it. Also, reading in PFD files would be very neat – I might just reuse code from fPic to do that.

    Let me know if you want to beta test it [OS X or Linux, Windows will be a tad more complex] and I’ll send you a beta.

  3. jdiwnab Says:

    I was thinking better as in faster, and also if transparencies in PNGs worked correctly. I’m currently using Windows and will help there, and I’m in the process of moving to linux, so I can help you there, too, in a little while.

  4. dda Says:

    Alright. As for speed, I have no idea yet – I’ll have to put up a benchmark first. PNGs are indeed handled correctly, transparency and all that, although I haven’t tested it. I’d like to rewrite the test app for fPic, which produced this image, which has, as you can see, transparency. It would be a good test too.

Leave a Reply

You must be logged in to post a comment.