(www-image-write-html): Add new argument `dest-dir'; change order of
authortomo <tomo>
Fri, 15 Apr 2005 14:09:00 +0000 (14:09 +0000)
committertomo <tomo>
Fri, 15 Apr 2005 14:09:00 +0000 (14:09 +0000)
arguments; expect `prev-file', `file' and `next-file' are relative
path; expect `prev-file' and `next-file' are omitted extensions.
(www-image-convert-images): Add new argument `dest-dir'; change order of
arguments; change `prev-file' and `next-file' to non-optional
arguments; modify for `www-image-write-html'.

www-image.el

index 619b0b4..21b1e26 100644 (file)
              (/ (* width percent) 100.0)
              (/ (* height percent) 100.0)))))
 
-(defun www-image-write-html (file-base grade
-                                      prev-file next-file
-                                      prev-grade next-grade)
+(defun www-image-write-html (dest-dir
+                            prev-file file next-file
+                            prev-grade grade next-grade)
   (with-temp-buffer
     (insert
      "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
             \"http://www.w3.org/TR/html4/loose.dtd\">\n")
     (insert "<head>\n")
-    (insert (format "<title>%s</title>\n"
-                   (file-name-nondirectory file-base)))
+    (insert (format "<title>%s</title>\n" file))
     (insert "</head>\n")
     (insert "<body>\n")
-    (insert (format "<h1>%s</h1>\n"
-                   (file-name-nondirectory file-base)))
+    (insert (format "<h1>%s</h1>\n" file))
 
     (if prev-file
-       (insert (format "<a href=\"%s.html\">"
-                       (file-name-sans-extension
-                        (file-name-nondirectory prev-file)))))
+       (insert (format "<a href=\"%s.html\">" prev-file)))
     (insert "[Previous]")
     (if prev-file
        (insert "</a>"))
     (insert "\n")
 
     (if next-file
-       (insert (format "<a href=\"%s.html\">"
-                       (file-name-sans-extension
-                        (file-name-nondirectory next-file)))))
+       (insert (format "<a href=\"%s.html\">" next-file)))
     (insert "[Next]")
     (if next-file
        (insert "</a>"))
@@ -48,7 +42,7 @@
     (if prev-grade
        (insert (format "<a href=\"../%s/%s.html\">"
                        prev-grade
-                       (file-name-nondirectory file-base))))
+                       file)))
     (insert "[Smaller]")
     (if prev-grade
        (insert "</a>"))
@@ -57,7 +51,7 @@
     (if next-grade
        (insert (format "<a href=\"../%s/%s.html\">"
                        next-grade
-                       (file-name-nondirectory file-base))))
+                       file)))
     (insert "[Larger]")
     (if next-grade
        (insert "</a>"))
     (insert "<a href=\"")
     (insert
      (if next-grade
-         (format "../%s/%s.html"
-                 next-grade
-                 (file-name-nondirectory file-base))
-       (concat "../fullsize/"
-              (file-name-nondirectory file-base) ".jpg")))
+         (format "../%s/%s.html" next-grade file)
+       (concat "../fullsize/" file ".jpg")))
     (insert "\">")
-    (insert (format "<img alt=\"%s\" src=\"%s.jpg\">"
-                   (file-name-nondirectory file-base)
-                   (file-name-nondirectory file-base)))
+    (insert (format "<img alt=\"%s\" src=\"%s.jpg\">" file file))
     (insert "</a>
 
 <hr>
 </html>
 ")
     (unless (file-exists-p
-            (expand-file-name (symbol-name grade)
-                              (file-name-directory file-base)))
+            (expand-file-name (symbol-name grade) dest-dir))
       (make-directory
-       (expand-file-name (symbol-name grade)
-                        (file-name-directory file-base))))
+       (expand-file-name (symbol-name grade) dest-dir)))
     (write-region (point-min)(point-max)
-                 (format "%s%s/%s.html"
-                         (file-name-directory file-base)
-                         grade
-                         (file-name-nondirectory file-base)))))
+                 (expand-file-name
+                  (concat file ".html")
+                  (expand-file-name (symbol-name grade)
+                                    dest-dir)))))
 
-(defun www-image-convert-images (filename &optional prev-file next-file)
+(defun www-image-convert-images (dest-dir
+                                prev-file file next-file)
   (let* ((ret
          (with-temp-buffer
-           (call-process "identify" nil t t filename)
+           (call-process "identify" nil t t file)
            (goto-char (point-min))
            (and (re-search-forward " \\([0-9]+\\)x\\([0-9]+\\) " nil t)
                 (cons (string-to-number (match-string 1))
     (setq rest dest)
     (while rest
       (setq spec (car rest))
-      (www-image-write-html (file-name-sans-extension filename)
-                           (aref spec 1)
-                           prev-file next-file
+      (www-image-write-html dest-dir
+                           (if prev-file
+                               (file-name-sans-extension
+                                (file-name-nondirectory prev-file)))
+                           (file-name-sans-extension
+                            (file-name-nondirectory file))
+                           (if next-file
+                               (file-name-sans-extension
+                                (file-name-nondirectory next-file)))
                            prev-grade
+                           (aref spec 1)
                            (if (nth 1 rest)
                                (aref (nth 1 rest) 1)))
       (call-process "convert" nil nil nil
                    "-resize" (format "%d%%" (aref spec 0))
-                   filename
-                   (format "%s/%s/%s.jpg"
-                           (file-name-directory filename)
-                           (aref spec 1)
-                           (file-name-sans-extension
-                            (file-name-nondirectory filename))))
+                   file
+                   (expand-file-name
+                    (concat
+                     (file-name-sans-extension
+                      (file-name-nondirectory file)) ".jpg")
+                    (expand-file-name
+                     (symbol-name (aref spec 1))
+                     dest-dir)))
       (setq prev-grade (aref spec 1))
       (setq rest (cdr rest)))
     (unless (file-exists-p
-            (expand-file-name "fullsize"
-                              (file-name-directory filename)))
+            (expand-file-name "fullsize" dest-dir))
       (make-directory
-       (expand-file-name "fullsize"
-                        (file-name-directory filename))))
+       (expand-file-name "fullsize" dest-dir)))
     (call-process "convert" nil nil nil
-                 filename
-                 (format "%s/fullsize/%s.jpg"
-                         (file-name-directory filename)
-                         (file-name-sans-extension
-                          (file-name-nondirectory filename))))
+                 file
+                 (expand-file-name
+                  (concat
+                   (file-name-sans-extension
+                    (file-name-nondirectory file)) ".jpg")
+                  (expand-file-name "fullsize" dest-dir)))
     dest))
 
 (let ((rest
        (append
        (directory-files
-        "/archives/RAID2/koukotsu/TAKUHON/" t "^[^0-9].*\\.TIF$")
+        "/archives/RAID2/koukotsu/TAKUHON/original/" 'full "^[^0-9].*\\.TIF$")
        (directory-files
-        "/archives/RAID2/koukotsu/TAKUHON/" t "^[0-9].*\\.TIF$"))
+        "/archives/RAID2/koukotsu/TAKUHON/original/" 'full "^[0-9].*\\.TIF$"))
        ;; (directory-files
        ;;  "/archives/RAID2/koukotsu/TAKUHON/" t "\\.TIF$")
        )
       file prev-file)
   (while rest
     (setq file (car rest))
-    (www-image-convert-images file prev-file (nth 1 rest))
+    (www-image-convert-images
+     "/archives/RAID2/koukotsu/TAKUHON/"
+     prev-file file (nth 1 rest))
     (setq prev-file file
          rest (cdr rest))))