Copyright | (c) Laurent P René de Cotret 2019 - present |
---|---|
License | BSD3 |
Maintainer | laurent.decotret@outlook.com |
Stability | unstable |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
This module defines two Hakyll compilers. The first one, resizeImageCompiler
,
is used to resize images to specific dimensions. The aspect ratio might not be the same.
The other compiler, scaleImageCompiler
, scales images to fit within a specified
box while preserving aspect ratio.
import Hakyll import Hakyll.Images ( loadImage , resizeImageCompiler , scaleImageCompiler ) hakyll $ do -- Resize all profile pictures with .png extensions to 64x48 match "profiles/**.png" $ do route idRoute compile $ loadImage >>= resizeImageCompiler 64 48 -- Scale images to fit within a 600x400 box match "images/**" $ do route idRoute compile $ loadImage >>= scaleImageCompiler 600 400 (... omitted ...)
Synopsis
- 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
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
.