Giter VIP home page Giter VIP logo

lisp-magick-wand's Introduction

This is a fork of LISP-MAGICK, by Hans Bulfone, released under the BSD license. It is compatible with recent versions of ImageMagick (> 6.6.9.7) 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:

  • Function names are lisp-ified. For example, MagickGetImageWidth becomes magick:get-image-width. Note that we omit any redundant Magick prefix.
  • Functions that return multiple results via pointer arguments return multiple values.
  • In most cases, a failed operation is signaled 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 CL-MAGICK, and the length parameter is omitted. nil is passed as a NULL pointer (but #() is not).

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)))

lisp-magick-wand's People

Contributors

ruricolist avatar

Watchers

Yrjänä Rankka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.