home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / scripts / ckermit / photoalbum.~2~ < prev    next >
Text File  |  2006-07-08  |  11KB  |  256 lines

  1. #!/usr/local/test/bin/wermit +
  2. #
  3. # Usage: photoalbum.ksc [ keyword=value [ keyword=value [ ... ] ] ]
  4. #
  5. # Make web site of pictures.
  6. # Assumes all pictures are jpg, in the current directory by themselves.
  7. #
  8. # Options (keywords):
  9. #   title="This will be the title"
  10. #   color=xxx      (foreground text color, default black)
  11. #   background=yyy (background color, default white)
  12. #   language=zzz   (english or spanish, default english)
  13. #   height=nnn     (height for thumbnails in pixels, default 72)
  14. #   noscale=n      (0 to scale photos, 1 not to scale, default 0)
  15. #
  16. # Makes an index page with thumbnails (or picture filenames if there are
  17. # no thumbnails) and then a page for each picture with forward, back, and
  18. # index links, with the ability to click on each picture to see the original.
  19. # Page can be in Spanish or English.
  20. #
  21. # Overwrites any previous versions of the .html pages each time you run it.
  22. #
  23. # If ImageMagick is available, it is used to generate generate thumbnails
  24. # for the index page.  Otherwise the index page just contains a list of
  25. # links to the individual HTML pages.  ImageMagick is here:
  26. #
  27. #   http://www.imagemagick.org/
  28. #
  29. # Alternatively if you can make thumbnails some other way, they will be used
  30. # if they are already there.  For each file xxx.jpg, the corresponding
  31. # thumbnail must be called xxx-t.jpg; all thumbnails should be the same height.
  32. #
  33. # Frank da Cruz, Columbia University, 9 July 2006
  34. #
  35. if llt \v(version) 800212 exit 1 C-Kermit 8.0.212 Dev.20 or later required.
  36. if < \v(buildid) 20060707 exit 1 C-Kermit 8.0.212 Dev.20 or later required.
  37.  
  38. def USAGE {
  39.     echo
  40.     echo { Usage: photoalbum.ksc [ keyword=value [ keyword=value [ ... ] ] ]}
  41.     echo
  42.     echo { Makes a website in a directory containing .jpg images.}
  43.     echo { Index page shows thumbnails of the images.}
  44.     echo
  45.     echo { Options (keywords):}
  46.     echo {   title="This will be the title"}
  47.     echo {   color=xxx      (foreground text color, default black)}
  48.     echo {   background=yyy (background color, default white)}
  49.     echo {   language=zzz   (english or spanish, default english)}
  50.     echo {   height=nnn     (height for thumbnails in pixels, default 72)}
  51.     echo {   noscale=n      (0 to scale photos, 1 not to scale, default 0)}
  52.     echo {   help           (print this message)}
  53.     echo
  54.     exit 0
  55. }
  56. # Command-line processing - title and options
  57.  
  58. .height = 72                # Default thumbnail height
  59. .noscale = 0                # Scale pictures to browser by default 
  60. .language = English            # Default text language is English
  61. .color = darkmagenta                    # Default text language is black
  62. .background = beige            # Default background color is white
  63.  
  64. for \%i 1 \v(argc)-1 1 {                # Parse each option
  65.     void \fkeywordvalue(\&_[\%i])    # This function does it
  66.     if eq "\v(lastkwval)" "help" usage    # If keyword was "help" give help
  67. }
  68. if not numeric \m(height) exit 1 Fatal - Height not numeric: \m(height)
  69. if not numeric \m(noscale) exit 1 Fatal - Noscale not numeric: \m(noscale)
  70.  
  71. if match english \m(language)* .language = English
  72. else if match spanish \m(language)* .language = Spanish
  73. else exit 1 Fatal - Language "\m(language)" not supported
  74.  
  75. show macro title color background language height noscale
  76.  
  77. undef \%h \%w                # Height and width clauses for HTML
  78. if not \m(noscale) {
  79.     .\%h = { height="90%"}        # Portrait
  80.     .\%w = { width="100%"}        # Landscape
  81. }
  82.  
  83. pwd
  84. if eq \m(system) unix chmod 664 *.jpg
  85.  
  86. # Use Image Magick 'convert' (if available) to create thumbnails.
  87.  
  88. dir /array:&t /except:*-t.jpg *.jpg     # Get list of non-thumbnail images
  89. .need_thumbnails = 0                    # Assume we don't need thumbnails
  90. if def height .need_thumbnails = 1      # If height given maybe we do
  91. if not \m(need_thumbnails) {            # Or...
  92.     .\%t := \ffiles(*-t.jpg)            # if we don't have a thumbnail for
  93.     if > \&t[0] \%t .need_thumbnails = 1 # every non-thumbnail
  94. }
  95. if \m(need_thumbnails) {                # Need thumbnails.
  96.     !convert -version > /dev/null       # Do we have Image Magick convert?
  97.     if fail {
  98.     echo Image Magick 'convert' not found - can't make thumbnails...
  99.         .need_thumbnails = 0
  100.     }
  101. }
  102. if \m(need_thumbnails) {                # Need to and can make thumbnails...
  103.     echo Creating thumbails...
  104.     for i 1 \&t[0] 1 {                  # Go through non-thumbnail jpgs...
  105.         .t := \fstripx(\fbasename(\&t[i]),.)
  106.         .tt := \m(t)-t.jpg              # Make name for thumbnail
  107.         if exist \m(tt) {               # Already exists?
  108.             if \fpictureinfo(\m(tt),&d) { # get its height
  109.                 if ( == \m(height) \&d[2] ) { # Same as requested height?
  110.                     continue                  # Nothing to do
  111.                 }
  112.             }
  113.             del /quiet \m(tt)           # Delete existing thumbnail
  114.         }
  115.         xecho " \&t[i]"                 # Create new thumbnail
  116.         !convert \&t[i] -geometry 500x\m(height) \m(tt)
  117.         if fail echo PROBLEM WITH \&t[i] - Continuing...
  118.         chmod 644 \m(tt)
  119.     }
  120.     echo                                # Done with thumbnails
  121. }
  122. .\%t := \ffiles(*-t.jpg)                # Now see how many thumbnails exist
  123.  
  124. # Localization (Spanish or English)...
  125.  
  126. .charset = iso-8859-1                   # Character set is ISO 8859-1
  127. undef langtag                           # No HMTL language tag yet
  128.  
  129. switch \m(language) {                   # Text messages for selected language
  130.   :spanish
  131.     .langtag = { lang="es"}             # HTML language tag
  132.     if not def title .title = Fotos     # Default title
  133.     .photo = Foto                       # Individual page title
  134.     .next  = Adelante                   # Forward
  135.     .prev  = Atrßs                      # Back
  136.     .index = Indice                     # Index
  137.     .up    = Arriba
  138.     .msg1  = Haz clic en cualquier nombre para ver fotos # Legend for index
  139.     if \%t .msg1 = Haz clic en cualquier foto para entrar
  140.     .msg2  = (Haz clic para ver en tama±o original)
  141.     break
  142.   :english
  143.     .langtag = { lang="en"}             # HTML language tag
  144.     if not def title .title = Photos    # Default title
  145.     .photo = Photo                      # Individual page title
  146.     .next  = Next                       # Forward
  147.     .prev  = Prev                       # Back
  148.     .index = Index                      # Index
  149.     .up    = Up
  150.     .msg1  = Click on any name to see photos # Legend for index
  151.     if \%t .msg1 = Click on any photo to enter
  152.     .msg2  = (Click to enlarge)
  153.     break
  154.   :default
  155.     stop 1 "No language!"
  156. }
  157. if \m(noscale) undef msg2
  158.  
  159. fopen /write \%o index.html             # Create the index page
  160. if fail stop 1 FOPEN index failed
  161.  
  162. # Write HTML prologue...
  163.  
  164. fwrite /line \%o <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  165. fwrite /line \%o <html\m(langtag)>
  166. fwrite /line \%o <head>
  167. fwrite /line \%o <title>\m(title)</title>
  168. fwrite /line \%o -
  169.   <META http-equiv="Content-Type" content="text/html; charset=\m(charset)">
  170. fwrite /line \%o </head>
  171. fwrite /line \%o <body bgcolor="\m(background)" text="\m(color)">
  172. fwrite /line \%o <h1>\m(title)</h1>
  173. fwrite /line \%o "( <a href="..">\m(up)</a> )  "
  174. fwrite /line \%o <i>(\m(msg1))</i><br>
  175.  
  176. dir /array:&a /except:*-t.jpg *.jpg     # Get list of non-thumbnail JPGs
  177. .\%n := \&a[0]                          # How many of these there are
  178. for \%i 1 \%n 1 {                       # Loop through all non-thumbnails
  179.     xecho "FILENAME \&a[\%i] => "       # Start to say what we're going
  180.     .\%b := \fstripx(\&a[\%i])          # Filename without ".jpg"
  181.     .\%f := \%b.html                    # Filename with ".html"
  182.     .orientation := \fpictureinfo(\&a[\%i]) # Get picture orientation
  183.     switch \m(orientation) {
  184.       :1, .\%p = "Landscape", break
  185.       :2, .\%p = "Portrait", break
  186.       :default, .\%p = "Unknown"
  187.     }
  188.     echo \%f (\%p)                      # Finish saying what we're doing
  189.     fopen /write \%c \%f                # Create page for this picture
  190.     if fail exit 1 OPEN failed
  191.     fwrite /line \%c -                  # Write HTML prologue
  192.       <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  193.     fwrite /line \%c <html\m(langtag)>
  194.     fwrite /line \%c <head>
  195.     fwrite /line \%c <title>\m(photo) \#\%i - \m(title)</title>
  196.     fwrite /line \%c -
  197.       <META http-equiv="Content-Type" content="text/html; charset=\m(charset)">
  198.     fwrite /line \%c </head>
  199.     fwrite /line \%c <body bgcolor="\m(background)" text="\m(color)">
  200.     fwrite /line \%c <h2>\m(photo) \#\%i</h2>
  201.     fwrite /line \%c
  202.  
  203.     if == \%i \%n {                     # If last picture there is no next.
  204.         fwrite /line \%c ( <a href="index.html">\m(index)</a> )
  205.     } else {                            # Not last picture
  206.     .\%x := \fstripx(\&a[\%i+1]).html # So make link to next.
  207.         fwrite /line \%c ( <a href="\%x">\m(next)</a> )
  208.     }
  209.     if != \%i 1 {                       # Not first picture?
  210.        .\%x := \fstripx(\&a[\%i-1]).html # Not first so link to previous
  211.        fwrite /line \%c "  ( <a href="\%x">\m(prev)</a> )  "
  212.     }
  213.     if != \%i \%n {                     # Not last picture?
  214.       fwrite /line \%c ( <a href="index.html">\m(index)</a> ) # Link to index
  215.     }
  216.     if def msg2 fwrite /line \%c <small><i>  \m(msg2)</i></small><br>
  217.     .\%x := \%b
  218.     .\%z = \fcontents(\%b)
  219.     if exist \%x.jpg .\%z = \fcontents(\%x)
  220.  
  221.     switch \%p {                        # Make image fit in browser screen
  222.       :Portrait                         # Portrait
  223.         if \m(noscale) {
  224.             fwrite /line \%c <img src="\%b.jpg"\%h>
  225.         } else {
  226.             fwrite /line \%c <a href="\%z.jpg"><img src="\%b.jpg"\%h></a>
  227.         }
  228.         break
  229.       :Landscape                        # Landscape
  230.         if \m(noscale) {
  231.             fwrite /line \%c <img src="\%b.jpg"\%h>
  232.         } else {
  233.             fwrite /line \%c <a href="\%z.jpg"><img src="\%b.jpg"\%w></a>
  234.         }
  235.         break
  236.       :default
  237.         fwrite /line \%c <img src="\%b.jpg">
  238.     }
  239.     fwrite /line \%c <hr color="\m(color)"> # End of page
  240.     fwrite /line \%c </body>
  241.     fwrite /line \%c </html>
  242.     fclose \%c
  243.     if eq \m(system) unix chmod 664 \%f
  244.     .\%x := \fstripx(\%f)-t             # Make entry in index page.
  245.     if exist \%x.jpg fwrite /line \%o {<a href="\%f"><img src="\%x.jpg"></a>}
  246.     else fwrite /line \%o [ <a href="\%f">\%f</a> ]
  247. }
  248. # Finish and close Index page
  249.  
  250. fwrite /line \%o <hr color="\m(color)"> # End of page
  251. fwrite /line \%o </body>
  252. fwrite /line \%o </html>
  253. fclose \%o
  254. if eq \m(system) unix chmod 664 index.html
  255. exit
  256.