Sculpin でページ生成時にサムネイルを作る Bundle 無いかなぁ?
無いなら作ろうかなぁ〜って思って Packagist を探してみたらそれらしいのを見つけたので試してみた。
見つけたのは beryllium/icelus - Packagist です。
Thumbnail generator for Sculpin-based websites
と書いてありました。
とりあえず使ってみる
完全な差分は IcelusBundle を追加してサムネイルを自動で生成するように変更 · sharkpp/www.sharkpp.net@68efa31 です。
インストール
sculpin.json
にパッケージを追加。
"components/jquery": "~1.9.1",
"components/highlightjs": "~7.3.0",
"jasny/twig-extensions": "@dev",
- "sharkpp/sculpin-calendarian-bundle": "dev-master"
+ "sharkpp/sculpin-calendarian-bundle": "dev-master",
+ "beryllium/icelus": "*"
},
"autoload": {
"psr-0": {
そして、おもむろに sculpin.phar update
を実行。
$ php sculpin.phar update
Loading composer repositories with package information
Updating dependencies
- Installing imanee/imanee (1.2.2)
Downloading: 100%
- Installing beryllium/icelus (1.0.0)
Downloading: 100%
Writing lock file
Generating autoload files
Compiling component files
app/SculpinKernel.php
にパッケージのクラスを追加。
protected function getAdditionalSculpinBundles()
{
return array(
- 'Sharkpp\Sculpin\Bundle\CalendarianBundle\SculpinCalendarianBundle'
+ 'Sharkpp\Sculpin\Bundle\CalendarianBundle\SculpinCalendarianBundle',
+ 'Beryllium\Icelus\IcelusBundle',
);
}
}
ファイルが存在しない場合は、 beryllium/icelus § Installation や Configuration — Sculpin を参考にして app/SculpinKernel.php
を作ってください。
使ってみる
の前に、どうやら Markdown Converter と相性というか、タイミングが悪いみたいで、
 }})
と記述すると、

と、このように惜しい感じになるので
<img src="{{ thumbnail('/images/noname/196x196.png', 64, 64) }}" alt="64 x 64">
と、HTMLのタグで直接記述しないとダメなようです。
元画像
64px のサムネイル
<img src="{{ thumbnail('/images/noname/196x196.png', 64, 64) }}" alt="64 x 64">
16px のサムネイル
<img src="{{ thumbnail('/images/noname/196x196.png', 16, 16) }}" alt="16 x 16">
ドキュメントのミスについて
あと、最初に使い方をドキュメントで見たところ、
<a href="image.jpg"><img src="{% thumbnail('image.jpg', 100, 100) %}"></a>
と記述してあったので素直にその通り書いて、実行したところ、
:
Generating: 100% (1079 sources / 0.17 seconds)
Converting: 14% [ Twig_Error_Syntax: Unexpected tag name "thumbnail" (expecting closing tag for the "for" tag defined near line 7) in "FileSource:FilesystemDataSource:~/git/test/source:test.html" at line 14 ]
[ Twig_Error_Syntax: Unexpected tag name "thumbnail" (expecting closing tag for the "for" tag defined near line 7) in "FileSource:FilesystemDataSource:~/git/test/source:test.html" at line 14 ]
100% (1722 sources / 7.49 seconds)
:
とエラーが出たので、
しばらく、これ実は使えない?とか、設定が足らない?とか思いながらしばらく試してみて、ふと
<a href="image.jpg"><img src="{{ thumbnail('image.jpg', 100, 100) }}"></a>
と書かないとダメなのではと思い試してみたところ、うまく動きました。
これは、 もう Pull Request するしかないと思ってサクッと PR しました。
設定について
icelus/DependencyInjection/Configuration.php とかを見ると設定で出力先などが変更できそうな気がしましたが、、、
他のソースを見ると使っている形跡がなく、そもそもドキュメントにも記載がないのできっと作りかけなのでしょう。