【发布时间】:2019-01-20 06:42:20
【问题描述】:
我正在尝试使用hakyll 和hakyll-images 来实现hakyll-images 自述文件中的一个示例,该示例执行我需要做的图像缩放。给定示例的类型不统一,我正在寻求有关如何进行的建议。
hakyll-images Readme 中的失败示例如下。
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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
错误是因为loadImage 定义的类型Image 是compile 要求的类型类Writable 的实例。 hakyll和hakyll-images使用的函数类型,抄自hackage文档,如下所示。
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 module 的文档中没有链接它的定义。
无论如何,hakyll-images 的自述文件中的示例似乎无法编译,因为Image 不是Writable 的实例。我想知道hakyll-images 包是否在某些时候与hakyll 不同步导致示例不再编译。
这个评估看起来正确吗? 您对我应该如何解决问题有什么建议?
我正在考虑:
- 通过为
Image添加一个Writable实例来更新hakyll-images。 - 使用其他一些函数集或函数组合来执行保持纵横比的图像缩放。
- 放弃
hakyll-images并寻找其他方法来缩放图像。
【问题讨论】: