hakyll-images-1.2.1: Hakyll utilities to work with images
Copyright(c) Laurent P René de Cotret 2019 - present
LicenseBSD3
Maintainerlaurent.decotret@outlook.com
Stabilityunstable
Portabilityportable
Safe HaskellSafe-Inferred
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

data JpgQuality Source #

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

Instances

Instances details
Enum JpgQuality Source # 
Instance details

Defined in Hakyll.Images.CompressJpg

Num JpgQuality Source # 
Instance details

Defined in Hakyll.Images.CompressJpg

Integral JpgQuality Source # 
Instance details

Defined in Hakyll.Images.CompressJpg

Real JpgQuality Source # 
Instance details

Defined in Hakyll.Images.CompressJpg

Eq JpgQuality Source # 
Instance details

Defined in Hakyll.Images.CompressJpg

Ord JpgQuality Source # 
Instance details

Defined in Hakyll.Images.CompressJpg

compressJpg :: Integral a => a -> 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.

In the rare case where the JPEG data contains transparency information, it will be dropped.

compressJpgCompiler :: Integral a => a -> 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). Values outside of this range will be normalized to the interval [0, 100]. 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.