(album-write-html): Add new argument `image-url-prefix'.
authortomo <tomo>
Mon, 18 Apr 2005 15:15:53 +0000 (15:15 +0000)
committertomo <tomo>
Mon, 18 Apr 2005 15:15:53 +0000 (15:15 +0000)
(album-convert-image): Rename argument `dest-dir' to `image-dest-dir';
add new arguments `html-dest-dir' and `image-url-prefix'.
(album-convert-images): Likewise.
(album-convert-directory): Likewise.

album.el

index 3b5bb79..529c188 100644 (file)
--- a/album.el
+++ b/album.el
@@ -41,7 +41,7 @@
              (/ (* width percent) 100.0)
              (/ (* height percent) 100.0)))))
 
-(defun album-write-html (dest-dir
+(defun album-write-html (dest-dir image-url-prefix
                         prev-file file next-file
                         prev-grade grade next-grade)
   (with-temp-buffer
          (format "../%s/%s.html" next-grade file)
        (concat "../fullsize/" file ".jpg")))
     (insert "\">")
-    (insert (format "<img alt=\"%s\" src=\"%s.jpg\">" file file))
+    (insert (format "<img alt=\"%s\" src=\"%s.jpg\">"
+                   file
+                   (if image-url-prefix
+                       (format "%s/%s/%s"
+                               image-url-prefix grade file)
+                     file)))
     (insert "</a>
 
 <hr>
                   (expand-file-name (symbol-name grade)
                                     dest-dir)))))
 
-(defun album-convert-image (dest-dir prev-file file next-file)
+(defun album-convert-image (image-dest-dir html-dest-dir image-url-prefix
+                                          prev-file file next-file)
   (setq file (expand-file-name file))
+  (unless html-dest-dir
+    (setq html-dest-dir image-dest-dir))
   (let* ((ret
          (with-temp-buffer
            (call-process "identify" nil t t file)
     (setq rest dest)
     (while rest
       (setq spec (car rest))
-      (album-write-html dest-dir
-                           (if prev-file
-                               (file-name-sans-extension
-                                (file-name-nondirectory prev-file)))
+      (album-write-html html-dest-dir image-url-prefix
+                       (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 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)))
+                            (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))
                    file
                       (file-name-nondirectory file)) ".jpg")
                     (expand-file-name
                      (symbol-name (aref spec 1))
-                     dest-dir)))
+                     image-dest-dir)))
       (setq prev-grade (aref spec 1))
       (setq rest (cdr rest)))
     (unless (file-exists-p
-            (expand-file-name "fullsize" dest-dir))
+            (expand-file-name "fullsize" image-dest-dir))
       (make-directory
-       (expand-file-name "fullsize" dest-dir)))
+       (expand-file-name "fullsize" image-dest-dir)))
     (if (string= (downcase (file-name-extension file))
                 "jpg")
        (call-process "ln" nil nil nil
                      "-f"
                      file
-                     (expand-file-name "fullsize" dest-dir))
+                     (expand-file-name "fullsize" image-dest-dir))
       (call-process "convert" nil nil nil
                    file
                    (expand-file-name
                     (concat
                      (file-name-sans-extension
                       (file-name-nondirectory file)) ".jpg")
-                    (expand-file-name "fullsize" dest-dir))))
+                    (expand-file-name "fullsize" image-dest-dir))))
     dest))
 
-(defun album-convert-images (dest-dir &rest source-images)
+(defun album-convert-images (image-dest-dir html-dest-dir
+                                           image-url-prefix
+                                           &rest source-images)
   (if (and (consp (car source-images))
           (null (cdr source-images)))
       (setq source-images (car source-images)))
   (let (file prev-file)
     (while source-images
       (setq file (car source-images))
-      (album-convert-image dest-dir
+      (album-convert-image image-dest-dir html-dest-dir
+                          image-url-prefix
                           prev-file file (nth 1 source-images))
       (setq prev-file file
            source-images (cdr source-images)))))
 
-(defun album-convert-directory (dest-dir source-dir &rest patterns)
+(defun album-convert-directory (image-dest-dir html-dest-dir
+                                              image-url-prefix
+                                              source-dir &rest patterns)
   (let (files)
     (if patterns
        (dolist (pat patterns)
              (directory-files
               source-dir 'full
               ".+\\.\\(tiff\\|jpg\\|JPG\\|jpeg\\|gif\\|png\\)$"))))
-    (album-convert-images dest-dir files)))
+    (album-convert-images image-dest-dir html-dest-dir
+                         image-url-prefix files)))
 
 
 (provide 'album)