Maintainer | diagrams-discuss@googlegroups.com |
---|---|
Safe Haskell | None |
A full-featured rendering backend for diagrams using Rasterific, implemented natively in Haskell (making it easy to use on any platform). Can create png, tif, bmp, jpg, and animated GIFs.
To invoke the Rasterific backend, you have three options.
- You can use the Diagrams.Backend.Rasterific.CmdLine module to create standalone executables which output images when invoked.
- You can use the
renderRasterific
function provided by this module, which gives you more flexible programmatic control over when and how images are output (making it easy to, for example, write a single program that outputs multiple images, or one that outputs images dynamically based on user input, and so on). - For the most flexibility (e.g. if you want access to the
resulting Rasterific value directly in memory without writing it to
disk), you can manually invoke the
renderDia
method from theBackend
instance forRasterific
. In particular,renderDia
has the generic type
renderDia :: b -> Options b v -> QDiagram b v m -> Result b v
(omitting a few type class constraints). b
represents the
backend type, v
the vector space, and m
the type of monoidal
query annotations on the diagram. Options
and Result
are
associated data and type families, respectively, which yield the
type of option records and rendering results specific to any
particular backend. For b ~ Rasterific
and v ~ R2
, we have
data Options Rasterific R2 = RasterificOptions { _rasterificSizeSpec :: SizeSpec2D -- ^ The requested size of the output , _rasterificBypassAdjust :: Bool -- ^ Should the 'adjustDia' step be bypassed during rendering? }
data family Render Rasterific R2 = 'R (RenderM ())'
type family Result Rasterific R2 = 'Image PixelRGBA8'
So the type of renderDia
resolves to
renderDia :: Rasterific -> Options Rasterific R2 -> QDiagram Rasterific R2 m -> 'Image PixelRGBA8'
which you could call like renderDia Rasterific (RasterificOptions (Width 250))
myDiagram
.
- data Rasterific = Rasterific
- type B = Rasterific
- data family Options b1 v1
- renderRasterific :: FilePath -> SizeSpec2D -> Word8 -> Diagram Rasterific R2 -> IO ()
- size :: Lens' (Options Rasterific R2) SizeSpec2D
- writeJpeg :: Word8 -> FilePath -> Result Rasterific R2 -> IO ()
Documentation
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.
type B = RasterificSource
data family Options b1 v1
Backend-specific rendering options.
renderRasterific :: FilePath -> SizeSpec2D -> Word8 -> Diagram Rasterific R2 -> IO ()Source