hakyll-images-1.1.1: Hakyll utilities to work with images
Copyright(c) Laurent P René de Cotret 2019
LicenseBSD3
Maintainerlaurent.decotret@outlook.com
Stabilityunstable
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Hakyll.Images

Description

This package defines a few Hakyll compilers. These compilers help deal with images in the context of Hakyll programs, such as JPEG compression or image resizing.

Items must be loaded before compilers can be used, like so:

    import Hakyll
    import Hakyll.Images        ( loadImage
                                , resizeImageCompiler
                                )

    hakyll $ do

        -- Resize all profile pictures with .png extensions to 64x48
        match "profiles/**.png" $ do
            route idRoute
            compile $ loadImage
                >>= resizeImageCompiler 64 48

        (... omitted ...)

Compilers can be sequenced easily as well:

    import Hakyll
    import Hakyll.Images        ( loadImage
                                , compressJpgCompiler
                                , scaleImageCompiler
                                )

    hakyll $ do

        -- Resize all JPEgs to fit inside of 800x600
        -- Also compress to a quality of 25/100
        match "pictures/**.jpg" $ do
            route idRoute
            compile $ loadImage
                >>= scaleImageCompiler 800 600
                >>= compressJpgCompiler 25

        (... omitted ...)
Synopsis

Documentation

data Image Source #

Instances

Instances details
Binary Image Source # 
Instance details

Defined in Hakyll.Images.Common

Methods

put :: Image -> Put #

get :: Get Image #

putList :: [Image] -> Put #

Writable Image Source # 
Instance details

Defined in Hakyll.Images.Common

Methods

write :: FilePath -> Item Image -> IO () #

loadImage :: Compiler (Item Image) Source #

Load an image from a file. This function can be combined with other compilers.

match "*.jpg" $ do
    route idRoute
    compile $ loadImage
        >>= compressJpgCompiler 50

type JpgQuality = Int Source #

Jpeg encoding quality, from 0 (lower quality) to 100 (best quality).

compressJpg :: JpgQuality -> Image -> Image Source #

Compress a JPG bytestring to a certain quality setting. The quality should be between 0 (lowest quality) and 100 (best quality). An error is raised if the image cannot be decoded, or if the encoding quality is out-of-bounds

compressJpgCompiler :: JpgQuality -> Item Image -> Compiler (Item Image) Source #

Compiler that compresses a JPG image to a certain quality setting. The quality should be between 0 (lowest quality) and 100 (best quality). An error is raised if the image cannot be decoded.

match "*.jpg" $ do
    route idRoute
    compile $ loadImage
        >>= compressJpgCompiler 50

type Width = Int Source #

resize :: Width -> Height -> DynamicImage -> DynamicImage Source #

Resize an image to specified width and height using the bilinear transform. The aspect ratio may not be respected.

In the process, an image is converted to RGBA8. Therefore, some information loss may occur.

resizeImageCompiler :: Width -> Height -> Item Image -> Compiler (Item Image) Source #

Compiler that resizes images to a specific dimensions. Aspect ratio may not be preserved.

match "*.png" $ do
    route idRoute
    compile $ loadImage
        >>= resizeImageCompiler 48 64

Note that in the resizing process, images will be converted to RGBA8. To preserve aspect ratio, take a look at scaleImageCompiler.

scale :: Width -> Height -> DynamicImage -> DynamicImage Source #

Scale an image to a size that will fit in the specified width and height, while preserving aspect ratio. Images might be scaled up as well.

In the process, an image is converted to RGBA8. Therefore, some information loss may occur.

To scale images down only, take a look at ensureFit.

scaleImageCompiler :: Width -> Height -> Item Image -> Compiler (Item Image) Source #

Compiler that rescales images to fit within dimensions. Aspect ratio will be preserved. Images might be scaled up as well.

match "*.tiff" $ do
    route idRoute
    compile $ loadImage
        >>= scaleImageCompiler 48 64

Note that in the resizing process, images will be converted to RGBA8. To ensure images are only scaled down, take a look at ensureFitCompiler.

ensureFit :: Width -> Height -> DynamicImage -> DynamicImage Source #

Scale an image down to a size that will fit in the specified width and height, while preserving aspect ratio.

In the process, an image is converted to RGBA8. Therefore, some information loss may occur.

To scale images up or down, take a look at scale.

ensureFitCompiler :: Width -> Height -> Item Image -> Compiler (Item Image) Source #

Compiler that ensures images will fit within dimensions. Images might be scaled down, but never up. Aspect ratio will be preserved.

match "*.tiff" $ do
    route idRoute
    compile $ loadImage
        >>= ensureFitCompiler 48 64

Note that in the resizing process, images will be converted to RGBA8. To allow the possibility of scaling up, take a look at scaleImageCompiler.