Skip to content

Latest commit

 

History

History
72 lines (54 loc) · 2.08 KB

README.md

File metadata and controls

72 lines (54 loc) · 2.08 KB

nimagemagick

nimagemagick is an ImageMagick 7.0 wrapper for Nim. It wraps the MagickCore and MagickWand APIs, though at this point it's mostly a "thin" wrapper. With time more functions will be covered by the wrapper for a convenient interface. See the current progress in src/nimagemagick.nim

The wrapper gets automatically generated at compile time using the nimterop package, which leverages the tree-sitter project.

Requires ImageMagick 7.0 or later. Run convert -version to check. Only tested on Linux.

Contributions are welcome.

Installation

nimble install https://github.com/zedeus/nimagemagick.git

Example usage

import nimagemagick

proc main =
  # create a new wand, and read the built-in logo image
  var wand = newWand("logo:")
  wand.resizeImage(200, 200)
  wand.displayImage()

  # save the image
  wand.writeImage("logo.png")

# genesis must be called to setup the MagickWand environment
genesis()

main()

# terminus must be called after the main proc has exited.
# If called inside main, the wands will be destroyed after
# the environment has terminated, leading to a segfault
terminus()

See other examples in the examples folder.

Notes

To use a function from MagickCore/MagickWand that doesn't yet have a wrapper in wand.nim, ptr MagickWand can be accessed via the impl field of any Wand object. Here's the example above without the convenience wrappers:

import nimagemagick

proc main =
  var wand = newWand()
  discard MagickReadImage(wand.impl, "logo:")
  discard MagickResizeImage(wand.impl, 200, 200, LanczosFilter)
  discard MagickDisplayImage(wand.impl, "")

MagickWandGenesis()
main()
MagickWandTerminus()

If you don't want to use the Wand object, replace newWand() with NewMagickWand(), and remember to call DestroyMagickWand(wand).