Gauche:WebImageViewer
Shiro (2003/02/10 19:56:17 PST): うちのカミサンはPCのことはさっぱり分からないので、 とりあえずWebブラウザの基本的な使い方とGoogleの使い方だけ教えて、 GNOMEのパネルに専用のアイコンを置いといて、 それを押すとMozillaが立ち上がるようにしている。 ホームページは一種のカスタムリンク集にしてある。
そんな彼女が、デジカメで撮った写真をいつでも見たいとおっしゃった。
GImageViewでさえ多分「複雑すぎる」と却下されそうなので、 Web経由で特定のディレクトリに置いたイメージファイルを見られるようにと、 とりあえず最低限の機能だけ(サムネイル作成、一覧、イメージファイル閲覧)を さくっと作ってみた。
Gaucheによるcgiプログラミングのサンプルということで。
#!/usr/bin/env gosh
(use srfi-1)
(use www.cgi)
(use file.util)
(use util.list)
(use text.html-lite)
(define *image-uri* "/images/camera")
(define *image-path* "/var/www/html/images/camera")
(define *thumb-rows* 6)
(define *thumb-cols* 4)
(define (check-thumbnail image-file)
(let ((imgpath (build-path *image-path* image-file))
(thumb (build-path *image-path* "thumbnails" image-file)))
(unless (and (file-exists? thumb)
(>= (file-mtime thumb) (file-mtime imgpath)))
(sys-system #`"/usr/bin/X11/convert -size 128x96 ,imgpath ,thumb"))
))
(define (cmd-browse)
(let1 thumbs (directory-list *image-path* :filter #/\.jpg$/)
(for-each check-thumbnail thumbs)
`(,(cgi-header)
,(html:html
(html:head (html:title "List"))
(html:body
(html:table
(map (lambda (row)
(list
(html:tr (map html:th row))
(html:tr (map (lambda (col)
(html:td
(html:a
:href #`"http://toccata/,(build-path *image-uri* col)"
(html:img :src (build-path *image-uri* "thumbnails" col)
))))
row))))
(slices thumbs *thumb-cols*))))))
))
(define (main args)
(cgi-main
(lambda (params)
(cmd-browse))))
Tags: CGI, text.html-lite, www.cgi