gd-3000.7.3: A Haskell binding to a subset of the GD graphics library

Safe Haskell | Safe-Inferred
Language | Haskell98

Graphics.GD.ByteString.Lazy

Contents

- Types
- Creating and copying images
- Memory management
- Loading images
  - JPEG
  - PNG
  - GIF
- Saving images
  - JPEG
  - PNG
  - GIF
- Getting image information
- Querying
- Manipulating images
- Drawing
- Text
- Colors

Synopsis

- data Image
- type Size = (Int, Int)
- type Point = (Int, Int)
- type Color = CInt
- newImage :: Size -> IO Image
- copyImage :: Image -> IO Image
- copyRegion :: Point -> Size -> Image -> Point -> Image -> IO ()
- copyRegionScaled :: Point -> Size -> Image -> Point -> Size -> Image -> IO ()
- withImage :: IO Image -> (Image -> IO b) -> IO b
- loadJpegFile :: FilePath -> IO Image
- loadJpegData :: Int -> Ptr a -> IO Image
- loadJpegByteString :: ByteString -> IO Image
- loadPngFile :: FilePath -> IO Image
- loadPngData :: Int -> Ptr a -> IO Image
- loadPngByteString :: ByteString -> IO Image
- loadGifFile :: FilePath -> IO Image
- loadGifData :: Int -> Ptr a -> IO Image
- loadGifByteString :: ByteString -> IO Image
- saveJpegFile :: Int -> FilePath -> Image -> IO ()
- saveJpegByteString :: Int -> Image -> IO ByteString
- savePngFile :: FilePath -> Image -> IO ()
- savePngByteString :: Image -> IO ByteString
- saveGifFile :: FilePath -> Image -> IO ()
- saveGifByteString :: Image -> IO ByteString
- imageSize :: Image -> IO (Int, Int)
- getPixel :: (Int, Int) -> Image -> IO Color
- resizeImage :: Int -> Int -> Image -> IO Image
- rotateImage :: Int -> Image -> IO Image
- fillImage :: Color -> Image -> IO ()
- drawFilledRectangle :: Point -> Point -> Color -> Image -> IO ()
- drawFilledEllipse :: Point -> Size -> Color -> Image -> IO ()
- drawLine :: Point -> Point -> Color -> Image -> IO ()
- drawArc :: Point -> Size -> Int -> Int -> Color -> Image -> IO ()
- antiAliased :: (Color -> Image -> IO a) -> Color -> Image -> IO a
- setPixel :: Point -> Color -> Image -> IO ()
- useFontConfig :: Bool -> IO Bool
- drawString :: ByteString -> Double -> Double -> Point -> ByteString -> Color -> Image -> IO (Point, Point, Point, Point)
- measureString :: ByteString -> Double -> Double -> Point -> ByteString -> Color -> IO (Point, Point, Point, Point)
- drawStringCircle :: Point -> Double -> Double -> Double -> ByteString -> Double -> ByteString -> ByteString -> Color -> Image -> IO ()
- rgb :: Int -> Int -> Int -> Color
- rgba :: Int -> Int -> Int -> Int -> Color
- toRGBA :: Color -> (Int, Int, Int, Int)

# Types

data Image Source #

type Size = (Int, Int) Source #

type Point = (Int, Int) Source #

type Color = CInt Source #

# Creating and copying images

newImage :: Size -> IO Image Source #

Create a new empty image.

copyImage :: Image -> IO Image Source #

Make a copy of an image.

copyRegion Source #

Arguments

:: Point | Source upper left-hand corner
-> Size | Size of copied region
-> Image | Source image
-> Point | Destination upper left-hand corner
-> Image | Destination image
-> IO () |

Copy a region of one image into another

copyRegionScaled Source #

Arguments

:: Point | Source upper left-hand corner
-> Size | Size of source region
-> Image | Source image
-> Point | Destination upper left-hand corner
-> Size | Size of destination region
-> Image | Destination image
-> IO () |

Copy a region of one image into another, rescaling the region

# Memory management

withImage Source #

Arguments

:: IO Image | Image creation action.
-> (Image -> IO b) | Some operation on the image. The result should not reference the `Image`.
-> IO b |

Creates an image, performs an operation on the image, and frees it. This function allows block scoped management of `Image` objects. If you are handling large images, the delay before the finalizer which frees the image runs may cause significant temporary extra memory use. Use this function to force the image to be freed as soons as you are done with it. Note that it is unsafe to hold on to the `Image` after the function is done.

# Loading images

## JPEG

loadJpegFile :: FilePath -> IO Image Source #

Load a JPEG image from a file.

loadJpegData Source #

Arguments

:: Int | Buffer size.
-> Ptr a | Buffer with image data.
-> IO Image |

Load a JPEG image from a buffer.

loadJpegByteString :: ByteString -> IO Image Source #

Load a JPEG image from a ByteString

## PNG

loadPngFile :: FilePath -> IO Image Source #

Load a PNG image from a file.

loadPngData Source #

Arguments

:: Int | Buffer size.
-> Ptr a | Buffer with image data.
-> IO Image |

Load a PNG image from a buffer.

loadPngByteString :: ByteString -> IO Image Source #

Load a PNG image from a ByteString

## GIF

loadGifFile :: FilePath -> IO Image Source #

Load a GIF image from a file.

loadGifData Source #

Arguments

:: Int | Buffer size.
-> Ptr a | Buffer with image data.
-> IO Image |

Load a GIF image from a buffer.

loadGifByteString :: ByteString -> IO Image Source #

Load a GIF image from a ByteString

# Saving images

## JPEG

saveJpegFile Source #

Arguments

:: Int | quality: 0-95, or negative for default quality.
-> FilePath |
-> Image |
-> IO () |

Save an image as a JPEG file.

saveJpegByteString :: Int -> Image -> IO ByteString Source #

Write a JPEG format ByteString of an image.

## PNG

savePngFile :: FilePath -> Image -> IO () Source #

Save an image as a PNG file.

savePngByteString :: Image -> IO ByteString Source #

Write a PNG format ByteString of an image.

## GIF

saveGifFile :: FilePath -> Image -> IO () Source #

Save an image as a GIF file.

saveGifByteString :: Image -> IO ByteString Source #

Write a GIF format ByteString of an image.

# Getting image information

imageSize Source #

Arguments

:: Image |
-> IO (Int, Int) | (width, height)

Get the size of an image.

# Querying

getPixel :: (Int, Int) -> Image -> IO Color Source #

Retrieves the color index or the color values of a particular pixel.

# Manipulating images

resizeImage Source #

Arguments

:: Int | width in pixels of output image
-> Int | height in pixels of output image
-> Image |
-> IO Image |

Resize an image to a give size.

rotateImage Source #

Arguments

:: Int | 1 for 90 degrees counter-clockwise, 2 for 180 degrees, etc.
-> Image |
-> IO Image |

Rotate an image by a multiple of 90 degrees counter-clockwise.

# Drawing

fillImage :: Color -> Image -> IO () Source #

Fill the entire image with the given color.

drawFilledRectangle Source #

Arguments

:: Point | Upper left corner
-> Point | Lower right corner
-> Color |
-> Image |
-> IO () |

drawFilledEllipse Source #

Arguments

:: Point | Center
-> Size | Width and height
-> Color |
-> Image |
-> IO () |

drawLine Source #

Arguments

:: Point | Start
-> Point | End
-> Color |
-> Image |
-> IO () |

drawArc Source #

Arguments

:: Point | Center
-> Size | Width and height
-> Int | Starting position (degrees)
-> Int | Ending position (degrees)
-> Color |
-> Image |
-> IO () |

antiAliased :: (Color -> Image -> IO a) -> Color -> Image -> IO a Source #

Use anti-aliasing when performing the given drawing function. This can cause a segault with some gd versions.

setPixel :: Point -> Color -> Image -> IO () Source #

# Text

useFontConfig :: Bool -> IO Bool Source #

Globally switch from using font file names to fontconfig paths | for fonts in drawString (and measureString).

drawString Source #

Arguments

:: ByteString | Font name
-> Double | Font point size
-> Double | Angle in counterclockwise radians
-> Point | Origin
-> ByteString | Text, including HTML entities
-> Color |
-> Image |
-> IO (Point, Point, Point, Point) | Bounding box of the drawn text

Draw a string using the FreeType 2.x library

measureString Source #

Arguments

:: ByteString | Font name
-> Double | Font point size
-> Double | Angle in counterclockwise radians
-> Point | Origin
-> ByteString | Text, including HTML entities
-> Color |
-> IO (Point, Point, Point, Point) | Bounding box of the drawn text

Measure a string using the FreeType 2.x library. This computes the bounding box but does not actually draw the string to any image.

drawStringCircle Source #

Arguments

:: Point | Center of text path circle
-> Double | Outer radius of text
-> Double | Fraction of radius occupied by text
-> Double | Portion of circle arc filled by text
-> ByteString | Font name
-> Double | Font size hint
-> ByteString | Text to write on the top of the circle
-> ByteString | Text to write on the bottom of the circle
-> Color | Text color
-> Image |
-> IO () |

Draw strings around the top and bottom of a torus

# Colors

rgb Source #

Arguments

:: Int | Red (0-255)
-> Int | Green (0-255)
-> Int | Blue (0-255)
-> Color |

rgba Source #

Arguments

:: Int | Red (0-255)
-> Int | Green (0-255)
-> Int | Blue (0-255)
-> Int | Alpha (0-127), 0 is opaque, 127 is transparent
-> Color |

toRGBA :: Color -> (Int, Int, Int, Int) Source #