Home

Awesome

Lisp-Magick-Wand

Common Lisp bindings to ImageMagick's MagicWand API.
This is a fork of LISP-MAGICK.
It is compatible with recent versions of ImageMagick (7.x) and has a slightly different API.

Usage

For the most part, you can use the C API as a reference. Translations follow a few simple rules:

Example

(defpackage :lisp-magick-examples
  (:use :cl))
(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."
  (magick: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."
  (magick:with-magick-wand (wand :create width height :comp (0 0 0))
    (magick:with-drawing-wand (dw)
      (magick:with-pixel-wand (pw :comp (255 255 255))
        (magick:draw-set-stroke-color dw pw))
      (magick:draw-set-stroke-width dw 3d0)
      (dotimes (i 50)
        (magick: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)))

Contributors