Skip to content

ImageMagick wrapper for Nim (MagickCore/MagickWand)

License

Notifications You must be signed in to change notification settings

zedeus/nimagemagick

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

ImageMagick wrapper for Nim (MagickCore/MagickWand)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages