+;;; www-image.el --- Album page generator for image.cgi.
+
+;; Copyright (C) 2005,2006 MORIOKA Tomohiko
+
+;; Keywords: Photo, image, album, HTML, WWW
+
+;; This file is part of Album.
+
+;; Album is free software; you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; Album is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;; It requires `convert' and `identify' of ImageMagick.
+
+;;; Code:
+
+(defvar www-image-coding-system
+ (if (featurep 'chise)
+ 'utf-8-jp-er
+ 'utf-8))
+
+(defvar www-image-default-base-directory
+ "../pub/pictures/")
+
+(defvar www-image-size-specs
+ '((thumbnail 160 160)
+ (QVGA 320 240)
+ (VGA 640 480)
+ (SVGA 800 600)
+ (XGA 1024 768)
+ (WXGA 1280 768)
+ (SXGA 1280 1024)
+ (SXGA+ 1400 1050)
+ (WSXGA+ 1680 1050)
+ (UXGA 1600 1200)
+ (WUXGA 1920 1200)
+ (QXGA 2048 1536)
+ (WQXGA 2560 1600)
+ ))
+
+(defun decode-url-string (string &optional coding-system)
+ (if (> (length string) 0)
+ (let ((i 0)
+ dest)
+ (while (string-match "%\\([0-9A-F][0-9A-F]\\)" string i)
+ (setq dest (concat dest
+ (substring string i (match-beginning 0))
+ (char-to-string
+ (int-char
+ (string-to-int (match-string 1 string) 16))))
+ i (match-end 0)))
+ (decode-coding-string
+ (concat dest (substring string i))
+ coding-system))))
+
+(defun www-image-display-thumbnails (url-dir &optional size image-root
+ lang title parent-url)
+ (setq url-dir (file-name-as-directory url-dir))
+ (let* ((desc-file
+ (expand-file-name "dir.desc"
+ (expand-file-name url-dir image-root)))
+ (params
+ (with-temp-buffer
+ (when (file-exists-p desc-file)
+ (insert-file-contents desc-file)
+ (read (current-buffer)))))
+ source-images
+ file
+ note)
+ (when (setq title (assq 'title params))
+ (setq title (cdr title)))
+ (unless title
+ (setq title
+ (file-name-nondirectory
+ (substring url-dir 0 (1- (length url-dir))))))
+ (when (setq source-images (assq 'files params))
+ (setq source-images (cdr source-images)))
+ (when (setq note (assq 'note params))
+ (setq note (cdr note)))
+ (when (setq parent-url (assq 'exit params))
+ (setq parent-url (cdr parent-url)))
+ (with-temp-buffer
+ (insert
+ "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
+ \"http://www.w3.org/TR/html4/loose.dtd\">\n")
+ (insert "<html")
+ (if lang
+ (insert (format " lang=\"%s\"" lang)))
+ (insert ">\n")
+ (insert "<head>\n")
+ (insert (format "<title>%s</title>\n" title))
+ (insert "</head>\n")
+ (insert "<body>\n")
+ (insert (format "<h1>%s</h1>\n" title))
+
+ (insert "
+<hr>
+")
+ (dolist (image-file source-images)
+ (setq file (file-name-nondirectory image-file))
+ (insert "<a href=\"image.cgi?page=")
+ (insert url-dir)
+ (insert file)
+ (insert (format "&size=%s&lang=%s\">"
+ (or size 'VGA)
+ (or lang 'en)))
+ (insert (format "<img alt=\"%s\" src=\"image.cgi?file=%s%s&size=thumbnail\">"
+ file url-dir file))
+ (insert "</a>\n"))
+
+ (when note
+ (insert "<p>")
+ (insert note))
+
+ (insert "
+
+<hr>
+")
+ (if parent-url
+ (insert (format "[<a href=\"%s\">Return</a>]\n" parent-url)))
+
+ (insert "
+</body>
+</html>
+")
+ (encode-coding-region (point-min)(point-max) www-image-coding-system)
+ (princ "Content-Type: text/html; charset=UTF-8
+
+")
+ (princ (buffer-string))
+ )))
+
+(defun www-image-display-page (file &optional size image-root
+ lang prev-file next-file)
+ (if (stringp size)
+ (setq size (intern size)))
+ (if (stringp lang)
+ (setq lang (intern lang)))
+ (princ "Content-Type: text/html; charset=UTF-8
+
+")