Copyright | (c) Laurent P René de Cotret 2019 |
---|---|
License | BSD3 |
Maintainer | laurent.decotret@outlook.com |
Stability | unstable |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
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
- data Image
- loadImage :: Compiler (Item Image)
- module Hakyll.Images.Metadata
- type JpgQuality = Int
- compressJpg :: JpgQuality -> Image -> Image
- compressJpgCompiler :: JpgQuality -> Item Image -> Compiler (Item Image)
- type Width = Int
- type Height = Int
- resize :: Width -> Height -> DynamicImage -> DynamicImage
- resizeImageCompiler :: Width -> Height -> Item Image -> Compiler (Item Image)
- scale :: Width -> Height -> DynamicImage -> DynamicImage
- scaleImageCompiler :: Width -> Height -> Item Image -> Compiler (Item Image)
- ensureFit :: Width -> Height -> DynamicImage -> DynamicImage
- ensureFitCompiler :: Width -> Height -> Item Image -> Compiler (Item Image)
Documentation
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
module Hakyll.Images.Metadata
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
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
.