我正在尝试使用hakyll
并hakyll-images
实现hakyll-images
自述文件中的一个示例,该示例执行我需要做的图像缩放。给定示例的类型不统一,我正在寻求有关如何进行的建议。
hakyll-images
自述文件中的失败示例如下。
import Hakyll
import Hakyll.Images ( loadImage
, scaleImageCompiler
)
main = hakyll $ do
-- Scale images to fit within a 600x400 box
-- Aspect ratio will be preserved
match "images/*" $ do
route idRoute
compile $ loadImage
>>= scaleImageCompiler 600 400
尝试编译会报错:
site.hs:12:9: error:
• No instance for (Writable
hakyll-images-0.3.1:Hakyll.Images.Common.Image)
arising from a use of ‘compile’
• In a stmt of a 'do' block:
compile $ loadImage >>= scaleImageCompiler 600 400
In the second argument of ‘($)’, namely
‘do route idRoute
compile $ loadImage >>= scaleImageCompiler 600 400’
In a stmt of a 'do' block:
match "images/*"
$ do route idRoute
compile $ loadImage >>= scaleImageCompiler 600 400
|
12 | compile $ loadImage >>= scaleImageCompiler 600 400
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
错误是因为Image
由 定义的typeloadImage
必须compile
是 typeclass 的实例Writable
。hakyll
从 hackage 文档中复制的和使用的函数类型hakyll-images
如下所示。
route :: Routes -> Rules ()
idRoute :: Routes
compile :: (Binary a, Typeable a, Writable a) => Compiler (Item a) -> Rules ()
loadImage :: Compiler (Item Image)
scaleImageCompiler :: Width -> Height -> Item Image -> Compiler (Item Image)
Image
定义hakyll-images
为type Image = Image_ ByteString
。我不确定是什么Image_
;它的定义未在该Hakyll.Images
模块的文档中链接。
无论如何,hakyll-images
由于Image
不是Writable
. 我想知道是否可能hakyll-images
包在某些时候变得不同步hakyll
导致示例不再编译。
这个评估似乎正确吗?您对我如何解决解决方案有什么建议?
我正在考虑:
- 通过
hakyll-images
以某种方式Writable
为Image
. - 使用其他一些功能集或组合来执行保持纵横比的图像缩放。
- 放弃
hakyll-images
并寻找其他方式来缩放图像。