lisp-magick

1. Authors

  • Hans Bulfone hans@nil.at

2. Short Description

An ImageMagick binding for Common Lisp

3. Download

4. Installation

lisp-magick can be installed with asdf-install. It requires cffi.

5. Usage

For documentation on the ImageMagick (MagickWand) API see the C-API documentation. The following conventions are used:

  • function names are lisp-ified, for example MagickGetImageWidth becomes magick-get-image-width
  • functions that return multiple results via pointer arguments return multiple values in lisp-magick.
  • in most cases a failed operation is signalled as magick-wand-error condition.
  • when a function expects an array of values and its length a vector or a list can be passed in lisp-magick and the length parameter is omitted. nil is passed as a NULL pointer (but #() is not).

A few with-style macros are provided to manage proper deallocation of ImageMagick resources. See utils.lisp.

The binding is not yet complete, but new functions can easily be added.

6. Examples

lisp-magick examples
(defpackage :lisp-magick-examples
  (:use :cl :lisp-magick))
(in-package :lisp-magick-examples)

(defun create-thumbnail (filename thumbname width height)
  "Create a thumbnail the image in FILENAME with a max size of WIDTH x HEIGHT
pixel (but with the original aspect ratio) and save it in THUMBNAME."
  (with-magick-wand (wand :load filename)
    (let ((a (/ (magick-get-image-width wand)
                (magick-get-image-height wand))))
      (if (> a (/ width height))
          (magick-scale-image wand width (truncate (/ width a)))
          (magick-scale-image wand (truncate (* a height)) height)))
    (magick-write-image wand thumbname)))

(defun draw-a-few-lines (filename width height)
  "Create a new image with WIDTH x HEIGHT pixel containing 50 random lines
and save it in FILENAME."
  (with-magick-wand (wand :create width height :comp (0 0 0))
    (with-drawing-wand (dw)
      (with-pixel-wand (pw :comp (255 255 255))
        (draw-set-stroke-color dw pw))
      (draw-set-stroke-width dw 3d0)
      (dotimes (i 50)
        (draw-line dw (coerce (random width) 'double-float)
                   (coerce (random height) 'double-float)
                   (coerce (random width) 'double-float)
                   (coerce (random height) 'double-float)))
      (magick-draw-image wand dw))
    (magick-write-image wand filename)))

7. License

Copyright (c) 2006, 2007, 2008, 2009  Hans Bulfone
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of his contributors may
      be used to endorse or promote products derived from this software
      without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Send comments, suggestions, etc. to me.