1 ;;; album.el --- Photo album utility
3 ;; Copyright (C) 2005 MORIOKA Tomohiko
5 ;; Keywords: Photo, image, album, HTML, WWW
7 ;; This file is part of Album.
9 ;; Album is free software; you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; Album is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; It requires `convert' and `identify' of ImageMagick.
30 (defun album-make-spec-by-width (width limit spec-name)
32 (let ((percent (floor (/ (* limit 100.0) width))))
33 (vector percent spec-name
34 (/ (* width percent) 100.0)
35 (/ (* height percent) 100.0)))))
37 (defun album-make-spec-by-height (height limit spec-name)
38 (when (> height limit)
39 (let ((percent (floor (/ (* limit 100.0) height))))
40 (vector percent spec-name
41 (/ (* width percent) 100.0)
42 (/ (* height percent) 100.0)))))
44 (defun album-write-html (dest-dir
45 prev-file file next-file
46 prev-grade grade next-grade)
49 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
50 \"http://www.w3.org/TR/html4/loose.dtd\">\n")
52 (insert (format "<title>%s</title>\n" file))
55 (insert (format "<h1>%s</h1>\n" file))
58 (insert (format "<a href=\"%s.html\">" prev-file)))
65 (insert (format "<a href=\"%s.html\">" next-file)))
72 (insert (format "<a href=\"../%s/%s.html\">"
81 (insert (format "<a href=\"../%s/%s.html\">"
95 (format "../%s/%s.html" next-grade file)
96 (concat "../fullsize/" file ".jpg")))
98 (insert (format "<img alt=\"%s\" src=\"%s.jpg\">" file file))
106 (unless (file-exists-p
107 (expand-file-name (symbol-name grade) dest-dir))
109 (expand-file-name (symbol-name grade) dest-dir)))
110 (write-region (point-min)(point-max)
112 (concat file ".html")
113 (expand-file-name (symbol-name grade)
116 (defun album-convert-image (dest-dir prev-file file next-file)
117 (setq file (expand-file-name file))
120 (call-process "identify" nil t t file)
121 (goto-char (point-min))
122 (and (re-search-forward " \\([0-9]+\\)x\\([0-9]+\\) " nil t)
123 (cons (string-to-number (match-string 1))
124 (string-to-number (match-string 2))))))
129 (cond ((>= width height)
130 (when (setq ret (album-make-spec-by-width width 2048 'QXGA))
131 (setq dest (cons ret dest)))
132 (when (setq ret (album-make-spec-by-width width 1600 'UXGA))
133 (setq dest (cons ret dest)))
134 (when (setq ret (album-make-spec-by-width width 1400 'SXGA+))
135 (setq dest (cons ret dest)))
136 (when (setq ret (album-make-spec-by-width width 1280 'SXGA))
137 (setq dest (cons ret dest)))
138 (when (setq ret (album-make-spec-by-width width 1024 'XGA))
139 (setq dest (cons ret dest)))
140 (when (setq ret (album-make-spec-by-width width 800 'SVGA))
141 (setq dest (cons ret dest)))
142 (when (setq ret (album-make-spec-by-width width 640 'VGA))
143 (setq dest (cons ret dest)))
146 (when (setq ret (album-make-spec-by-height height 1536 'QXGA))
147 (setq dest (cons ret dest)))
148 (when (setq ret (album-make-spec-by-height height 1200 'UXGA))
149 (setq dest (cons ret dest)))
150 (when (setq ret (album-make-spec-by-height height 1050 'SXGA+))
151 (setq dest (cons ret dest)))
152 (when (setq ret (album-make-spec-by-height height 960 'SXGA))
153 (setq dest (cons ret dest)))
154 (when (setq ret (album-make-spec-by-height height 768 'XGA))
155 (setq dest (cons ret dest)))
156 (when (setq ret (album-make-spec-by-height height 600 'SVGA))
157 (setq dest (cons ret dest)))
158 (when (setq ret (album-make-spec-by-height height 480 'VGA))
159 (setq dest (cons ret dest)))
163 (setq spec (car rest))
164 (album-write-html dest-dir
166 (file-name-sans-extension
167 (file-name-nondirectory prev-file)))
168 (file-name-sans-extension
169 (file-name-nondirectory file))
171 (file-name-sans-extension
172 (file-name-nondirectory next-file)))
176 (aref (nth 1 rest) 1)))
177 (call-process "convert" nil nil nil
178 "-resize" (format "%d%%" (aref spec 0))
182 (file-name-sans-extension
183 (file-name-nondirectory file)) ".jpg")
185 (symbol-name (aref spec 1))
187 (setq prev-grade (aref spec 1))
188 (setq rest (cdr rest)))
189 (unless (file-exists-p
190 (expand-file-name "fullsize" dest-dir))
192 (expand-file-name "fullsize" dest-dir)))
193 (if (string= (downcase (file-name-extension file))
195 (call-process "ln" nil nil nil
198 (expand-file-name "fullsize" dest-dir))
199 (call-process "convert" nil nil nil
203 (file-name-sans-extension
204 (file-name-nondirectory file)) ".jpg")
205 (expand-file-name "fullsize" dest-dir))))
208 (defun album-convert-images (dest-dir &rest source-images)
209 (if (and (consp (car source-images))
210 (null (cdr source-images)))
211 (setq source-images (car source-images)))
212 (let (file prev-file)
214 (setq file (car source-images))
215 (album-convert-image dest-dir
216 prev-file file (nth 1 source-images))
218 source-images (cdr source-images)))))
220 (defun album-convert-directory (dest-dir source-dir &rest patterns)
223 (dolist (pat patterns)
226 (directory-files source-dir 'full pat))))
228 (let (case-fold-search)
231 ".+\\.\\(tiff\\|jpg\\|JPG\\|jpeg\\|gif\\|png\\)$"))))
232 (album-convert-images dest-dir files)))
237 ;;; album.el ends here