diagrams-rasterific-0.1: Rasterific backend for diagrams.

Copyright(c) 2014 Diagrams team (see LICENSE)
LicenseBSD-style (see LICENSE)
Safe HaskellNone




Convenient creation of command-line-driven executables for rendering diagrams using the Rasterific backend. Create png, tif, bmp, jpg or animated GIF files.

  • defaultMain creates an executable which can render a single diagram at various options.
  • multiMain is like defaultMain but allows for a list of diagrams from which the user can choose one to render.
  • animMain is like defaultMain but for animations instead of diagrams.
  • gifMain creates an executable to generate an animated GIF.
  • mainWith is a generic form that does all of the above but with a slightly scarier type. See Diagrams.Backend.CmdLine. This form can also take a function type that has a suitable final result (any of arguments to the above types) and Parseable arguments.

If you want to generate diagrams programmatically---i.e. if you want to do anything more complex than what the below functions provide---you have several options.

  • Use a function with mainWith. This may require making Parseable instances for custom argument types.
  • Make a new Mainable instance. This may require a newtype wrapper on your diagram type to avoid the existing instances. This gives you more control over argument parsing, intervening steps, and diagram creation.
  • Build option records and pass them along with a diagram to mainRender from Diagrams.Backend.CmdLine.
  • You can use renderRasterific to render a diagram to a file directly; see Diagrams.Backend.Rasterific.
  • A more flexible approach is to directly call renderDia; see Diagrams.Backend.Rasterific for more information.

For a tutorial on command-line diagram creation see http://projects.haskell.org/diagrams/doc/cmdline.html.


General form of main

mainWith :: (Mainable d, Parseable (MainOpts d)) => d -> IO ()

Supported forms of main

defaultMain :: Diagram Rasterific R2 -> IO () Source

multiMain :: [(String, Diagram Rasterific R2)] -> IO () Source

multiMain is like defaultMain, except instead of a single diagram it takes a list of diagrams paired with names as input. The generated executable then takes a --selection option specifying the name of the diagram that should be rendered. The list of available diagrams may also be printed by passing the option --list.

Example usage:

$ ghc --make MultiTest
[1 of 1] Compiling Main             ( MultiTest.hs, MultiTest.o )
Linking MultiTest ...
$ ./MultiTest --list
Available diagrams:
  foo bar
$ ./MultiTest --selection bar -o Bar.png -w 200

animMain :: Animation Rasterific R2 -> IO () Source

animMain is like defaultMain, but renders an animation instead of a diagram. It takes as input an animation and produces a command-line program which will crudely "render" the animation by rendering one image for each frame, named by extending the given output file name by consecutive integers. For example if the given output file name is foo/blah.png, the frames will be saved in foo/blah001.png, foo/blah002.png, and so on (the number of padding digits used depends on the total number of frames). It is up to the user to take these images and stitch them together into an actual animation format (using, e.g. ffmpeg).

Of course, this is a rather crude method of rendering animations; more sophisticated methods will likely be added in the future.

The --fpu option can be used to control how many frames will be output for each second (unit time) of animation.

gifMain :: [(Diagram Rasterific R2, GifDelay)] -> IO () Source

GIF support

data GifOpts Source

Extra options for animated GIFs.




Parseable GifOpts

Command line parser for GifOpts. --dither turn dithering on. --looping-off turn looping off, i.e play GIF once. --loop-repeat number of times to repeat the GIF after the first playing. this option is only used if --looping-off is not set.

Backend tokens

data Rasterific Source

This data declaration is simply used as a token to distinguish the Rasterific backend: (1) when calling functions where the type inference engine would otherwise have no way to know which backend you wanted to use, and (2) as an argument to the Backend and Renderable type classes.


Eq Rasterific 
Ord Rasterific 
Read Rasterific 
Show Rasterific 
Typeable * Rasterific 
Backend Rasterific R2 
Renderable Text Rasterific 
Mainable [(String, Diagram Rasterific R2)] 
Mainable [(Diagram Rasterific R2, GifDelay)] 
Renderable (DImage Embedded) Rasterific 
Renderable (Path R2) Rasterific 
Show (Options Rasterific R2) 
Monoid (Render Rasterific R2) 
Mainable (Animation Rasterific R2) 
Mainable (Diagram Rasterific R2) 
type Result Rasterific R2 = Image PixelRGBA8 
data Options Rasterific R2 = RasterificOptions {} 
data Render Rasterific R2 = R (RenderM ()) 
type MainOpts [(String, Diagram Rasterific R2)] = (MainOpts (Diagram Rasterific R2), DiagramMultiOpts) 
type MainOpts [(Diagram Rasterific R2, GifDelay)] = (DiagramOpts, GifOpts) 
type MainOpts (Animation Rasterific R2) = (MainOpts (Diagram Rasterific R2), DiagramAnimOpts) 
type MainOpts (Diagram Rasterific R2) = (DiagramOpts, DiagramLoopOpts)