September 15, 2003

Edi Weitz's CL-GD is a lisp wrapper around the GD graphics library.

This example, from Edi's page, creates a little pie chart.

programmaticallly created pie chart

(with-image* (200 200) ; create 200x200 pixel image
  (allocate-color 68 70 85) ; background color
  (let ((beige (allocate-color 222 200 81))
        (brown (allocate-color 206 150 75))
        (green (allocate-color 104 156 84))
        (red (allocate-color 163 83 84))
        (white (allocate-color 255 255 255))
        (two-pi (* 2 pi)))
    ;; move origin to center of image
    (with-transformation (:x1 -100 :x2 100 :y1 -100 :y2 100 :radians t)
      ;; draw some 'pie slices'
      (draw-arc 0 0 130 130 0 (* .6 two-pi)
                :center-connect t :filled t :color beige)
      (draw-arc 0 0 130 130 (* .6 two-pi) (* .8 two-pi)
                :center-connect t :filled t :color brown)
      (draw-arc 0 0 130 130 (* .8 two-pi) (* .95 two-pi)
                :center-connect t :filled t :color green)
      (draw-arc 0 0 130 130 (* .95 two-pi) two-pi
                :center-connect t :filled t :color red)
      (with-default-color (white)
        (with-default-font (:small)
          (draw-string -8 -30 "60%")
          (draw-string -20 40 "20%")
          (draw-string 20 30 "15%"))
        (draw-freetype-string -90 75 "Global Revenue"
                              ;; this assumes that 'DEFAULT_FONTPATH'
                              ;; is set correctly
                              :font-name "verdanab"))))
  (write-image-to-file "chart.png"
                       :compression-level 6 :if-exists :supersede))

CL-GD uses Kevin Rosenberg's UFFI portable FFI, so if your lisp is one of the ones supported by UFFI there's a decent chance CL-GD will work with it.

Posted by jjwiseman at September 15, 2003 06:38 PM

Now, that looks nice. I've been using Ruby GDChart bindings for a while, but using them don't feel as 'native' as this snippet.

Posted by: Eugene Zaikonnikov on September 16, 2003 02:37 AM

Oooh, finally Lisp is able to do what PHP has done for years! :-P I believe the PHP crew has actually taken over gd development or forked it or something.

Posted by: Troutgirl on September 18, 2003 11:37 PM

I don't think so. It'll take at least some more years. It will be hard work to emulate all of PHP's bugs and inconsistencies. Not to mention that there are very many PHP coders and only very few Lisp hackers. They'll introduce new bugs much too fast for us to follow.

Posted by: Edi Weitz on September 19, 2003 08:17 AM

Heh. Sorry Edi, wasn't trying to bogue on your parade.

Posted by: Troutgirl on September 19, 2003 04:08 PM

No problem. It's just that I had to work with PHP for the last four years and I really know it's junk. I can't understand everybody uses it. (Or maybe I can. Must be the same reason everyone uses Wintendo... :)

Posted by: Edi Weitz on September 20, 2003 02:15 AM

Edi said:
> I can't understand [why] everybody uses [PHP].

Ah, Edi-Grasshopper. You look far and wide for answers to your perplexity, but they can be found within the very thread that you post to. Even within your own postings, if you look hard enough.

Posted by: timboy on September 22, 2003 09:25 PM
Post a comment

Email Address:


Unless you answer this question, your comment will be classified as spam and will not be posted.
(I'll give you a hint: the answer is “lisp”.)


Remember info?