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