;;; 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
"\n")
(insert "\n")
(insert "
\n")
(insert (format "%s\n" title))
(insert "\n")
(insert "\n")
(insert (format "%s
\n" title))
(insert "
")
(dolist (image-file source-images)
(setq file (file-name-nondirectory image-file))
(insert ""
(or size 'VGA)
(or lang 'en)))
(insert (format ""
file url-dir file))
(insert "\n"))
(when note
(insert "")
(insert note))
(insert "
")
(if parent-url
(insert (format "[Return]\n" parent-url)))
(insert "
")
(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
")
(with-temp-buffer
(insert
"\n")
(insert "\n")
;; (insert (format "%s
\n" file))
(let* ((desc-file (expand-file-name (concat file ".desc") image-root))
(params
(with-temp-buffer
(when (file-exists-p desc-file)
(insert-file-contents desc-file)
(read (current-buffer)))))
dir-desc-file
prev-file next-file
prev-grade next-grade
rest spec ret)
(unless params
(setq dir-desc-file
(expand-file-name "dir.desc"
(expand-file-name (file-name-directory file)
image-root)))
(setq params
(with-temp-buffer
(when (file-exists-p dir-desc-file)
(insert-file-contents dir-desc-file)
(read (current-buffer)))))
(when (setq rest (assq 'files params))
(setq rest (cdr rest)))
(setq ret (file-name-nondirectory file))
(while (and rest
(not (string= (car rest) ret)))
(setq prev-file (car rest)
rest (cdr rest)))
(setq next-file (car (cdr rest)))
(if prev-file
(setq params (list (cons 'prev-file prev-file))))
(if next-file
(setq params (cons (cons 'next-file next-file)
params)))
(with-temp-buffer
(insert (format "%S" params))
;; (princ "X-XEmacs-Message: ")
(write-region (point-min)(point-max) desc-file)
;; (princ "\n")
))
(if (setq prev-file (assq 'prev-file params))
(setq prev-file (cdr prev-file)))
(if (setq next-file (assq 'next-file params))
(setq next-file (cdr next-file)))
(setq rest www-image-size-specs)
(while (and rest
(setq spec (car rest))
(not (eq (car spec) size)))
(setq prev-grade (car spec)
rest (cdr rest)))
(setq next-grade (car (car (cdr rest))))
(if prev-file
(insert (format ""
(file-name-directory file) prev-file size
(or lang 'en))))
(cond ((eq lang 'ja)
(insert "[前]")
)
(t
(insert "[Previous]")
))
(if prev-file
(insert ""))
(insert "\n")
(if next-file
(insert (format ""
(file-name-directory file) next-file size
(or lang 'en))))
(cond ((eq lang 'ja)
(insert "[次]")
)
(t
(insert "[Next]")
))
(if next-file
(insert ""))
(insert "\n")
(if prev-grade
(insert (format ""
file prev-grade
(or lang 'en))))
(cond ((eq lang 'ja)
(insert "[縮小]")
)
(t
(insert "[Smaller]")
))
(if prev-grade
(insert ""))
(insert "\n")
(if next-grade
(insert (format ""
file next-grade
(or lang 'en))))
(cond ((eq lang 'ja)
(insert "[拡大]")
)
(t
(insert "[Larger]")
))
(if next-grade
(insert ""))
(insert "\n")
(insert "
")
(if next-file
(insert (format ""
(file-name-directory file) next-file size
(or lang 'en))))
(insert (format ""
file file size))
(if next-file
(insert ""))
(insert "
")
(insert
(format "[index]"
(file-name-directory file) size (or lang 'en)))
(insert "