yesod-media-simple-0.2.0.0: Simple display of media types, served by yesod

Safe HaskellNone
LanguageHaskell98

Yesod.Media.Simple

Contents

Description

Easily serve different media types to the user.

Synopsis

Documentation

serve :: RenderContent a => a -> IO () Source

Starts a web server which serves the given data to the client. It listens on the port specified by the PORT environment variable. If there is no PORT variable, it defaults to port 3000. This means that the results will be visible at http://localhost:3000. The server responds to any GET request with the results - the route is ignored.

serveHandler :: RenderContent a => LiteHandler a -> IO () Source

Like serve, but the media to render results from a LiteHandler action. This allows the data to render to be computed within the LiteHandler monad, allowing it to respond particularly to the user's request.

Diagrams

Cairo is used to render diagrams to pngs.

serveDiagram :: Diagram Cairo -> IO () Source

A type-specialized version of serve. This is usually preferred to serve because Diagrams tend to be polymorphic - this fixes the input data to be a Diagram Cairo.

data SizedDiagram Source

SizedDiagram can be used to specify the output size of the diagram when rendering it with Cairo.

Images

The various types of Image from JuicyPixels (Codec.Picture) are servable as pngs, unless the Jpeg wrapper type is used.

data PixelList Source

This type wraps RGB8 image data stored in nested lists, so that you don't need to use Codec.Picture. The inner list is one row of the image, and the tuple elements are the red green blue values, respectively.

Constructors

PixelList Int Int [[(Word8, Word8, Word8)]] 

data Jpeg Source

This type wraps image data that is appropriate for JPEG export, along with the requested quality (from 0 to 100).

Constructors

Jpeg Word8 (Image PixelYCbCr8) 

Utilities

imageToDiagramEmb :: (Renderable (DImage (N b) Embedded) b, V b ~ V2, TypeableFloat (N b)) => DynamicImage -> Diagram b Source

Convert a JuicyPixels Image to an image embedded in the Diagram. Note that this image is *NOT* renderable by the Cairo backend, which is used by other functions in this module.

imageToDiagramExt :: (Renderable (DImage (N b) External) b, V b ~ V2, TypeableFloat (N b)) => DynamicImage -> IO (Diagram b) Source

Write a JuicyPixels Image to a file in the system temp directory, and create a diagram which references this Image file. Unlike imageToDiagramEmb, this Diagram can be rendered by the Cairo backend.