support thumbnails
authorgc <gc>
Sat, 5 Mar 2005 22:49:33 +0000 (22:49 +0000)
committergc <gc>
Sat, 5 Mar 2005 22:49:33 +0000 (22:49 +0000)
booh
themes/simple/parameters.rb
themes/simple/skeleton.html
themes/simple/skeleton_thumbnails.html [new file with mode: 0644]

diff --git a/booh b/booh
index a708991ffc9fef5a9ae42a3d4932238ad9231000..22fa07d5391ed3fae46ba7a7aae276f1a67e8859 100755 (executable)
--- a/booh
+++ b/booh
@@ -58,7 +58,13 @@ $verbose_level = 2
 $captions = {}
 
 def __(string, *args)
-    sprintf(_(string), args)
+    if args.size == 0
+        _(string)
+    elsif args.size == 1
+        sprintf(_(string), args[0])
+    elsif args.size == 2
+        sprintf(_(string), args[0], args[1])
+    end
 end
 
 def usage
@@ -126,12 +132,12 @@ def handle_options
                     die __('Captions skeleton file already exists, won\'t overwrite')
                 else
                     $captions_skel = arg
-                    $images_list_for_captions = Array.new
+                    $images_list_for_captions = []
                 end
 
             when '--mproc'
                 $mproc = arg.to_i
-                $pids = Array.new
+                $pids = []
 
             when '--verbose-level'
                 $verbose_level = arg.to_i
@@ -159,12 +165,14 @@ def handle_options
         die __("Size %s not found in parameters of theme.", $size)
     else
         $sizeval = size['size']
-        msg 3, __("Using size for fullscreen images of value: %s", $sizeval)
+        $sizeval_thumbnails = size['thumbnails']
+        msg 3, __("Using sizes: fullscreen=%s, thumbnails=%s", $sizeval, $sizeval_thumbnails)
     end
 end
 
 def select_theme(name)
     $theme = name
+    msg 3, __("Selecting theme `%s'", $theme)
     themedir = "#{$FPATH}/themes/#{$theme}"
     if !File.directory?(themedir)
         die __("Theme was not found (tried %s directory).", themedir)
@@ -176,8 +184,6 @@ def use_captions(filename)
     for line in IO.readlines(filename)
         if line =~ /(\S+): (.+)/
             $captions[$1] = $2
-        else
-            die __("Unrecognized line in %s: %s", filename, line)
         end
     end
 end
@@ -202,15 +208,14 @@ def replace_line(surround, keyword, line)
     end
 end
 
-def build_html_skeleton
-    theme_file = File.open("#{$FPATH}/themes/#{$theme}/skeleton.html").readlines
-    msg 2, __("Read theme `%s'", $theme)
-    for line in theme_file
+def build_html_skeletons
+    $html_images     = File.open("#{$FPATH}/themes/#{$theme}/skeleton.html").readlines
+    $html_thumbnails = File.open("#{$FPATH}/themes/#{$theme}/skeleton_thumbnails.html").readlines
+    for line in $html_images + $html_thumbnails
         while line =~ /~~~(\w+)~~~/
             replace_line('~~~', $1, line)
         end
     end
-    return theme_file
 end
 
 #- parallelizable sys
@@ -219,7 +224,7 @@ def psys(cmd)
         if pid = fork
             $pids << pid
         else
-            msg 1, cmd + ' &'
+            msg 2, cmd + ' &'
             system(cmd)
             exit 0
         end
@@ -229,7 +234,7 @@ def psys(cmd)
             $pids = $pids.find_all { |pid| Process.waitpid(pid, Process::WNOHANG) == nil }
         end
     else
-        msg 1, cmd
+        msg 2, cmd
         system(cmd)
     end
 end
@@ -246,20 +251,24 @@ def walk_source_dir
         dir.chomp!
         msg 2, __("Examining %s...", dir)
         images = Dir["#{dir}/*.{jpg,JPG,jpeg,JPEG,gif,GIF,bmp,BMP,png,PNG}"]
-        msg 2, __("\t%s images", images.length)
+        msg 3, __("\t%s images", images.length)
         videos = Dir["#{dir}/*.{mov,MOV,avi,AVI,mpg,MPG,mpeg,MPEG,wmv,WMV,asx,ASX}"]
-        msg 2, __("\t%s videos", videos.length)
+        msg 3, __("\t%s videos", videos.length)
         
         dest_dir = dir.sub(/^#{Regexp.quote($source)}/, $dest)
         system("mkdir -p '#{dest_dir}'")
         msg 2, __("Outputting in %s...", dest_dir)
 
-        final_images = []
+        #- resizes
+        fullscreen_images = []
+        thumbnail_images = []
         images.each { |img|
-            dest_img = img.sub(/^#{Regexp.quote($source)}/, $dest).
-                           sub(/\.[^\.]+$/, '') + "-#{$sizeval}.jpg"
-            final_images << File.basename(dest_img)
-            if !File.exists?(dest_img)
+            base_dest_img = img.sub(/^#{Regexp.quote($source)}/, $dest).sub(/\.[^\.]+$/, '')
+            fullscreen_dest_img = base_dest_img + "-#{$sizeval}.jpg"
+            thumbnail_dest_img  = base_dest_img + "-#{$sizeval_thumbnails}.jpg"
+            fullscreen_images << File.basename(fullscreen_dest_img)
+            thumbnail_images  << File.basename(thumbnail_dest_img)
+            if !File.exists?(fullscreen_dest_img) || !File.exists?(thumbnail_dest_img)
                 convert_options = ''
                 orientation = `exif #{img}`.detect { |line| line =~ /^Orientation/ }
                 if orientation =~ /right - top/
@@ -268,20 +277,92 @@ def walk_source_dir
                 if orientation =~ /left - bottom/
                     convert_options += '-rotate -90 '
                 end
-                psys("#{$convert} #{convert_options}-geometry #{$sizeval} '#{img}' '#{dest_img}'")
+                if !File.exists?(fullscreen_dest_img)
+                    psys("#{$convert} #{convert_options}-geometry #{$sizeval} '#{img}' '#{fullscreen_dest_img}'")
+                end
+                if !File.exists?(thumbnail_dest_img)
+                    psys("#{$convert} #{convert_options}-geometry #{$sizeval_thumbnails} '#{img}' '#{thumbnail_dest_img}'")
+                end
+            end
+        }
+
+        #- index.html (page with thumbnails)
+        html = $html_thumbnails.collect { |l| l.clone }
+        iterations = {}
+        for i in html
+            i.sub!(/~~run_slideshow~~/, _('Run slideshow!'))
+            i.sub!(/~~title~~/, File.basename(dir))
+            if i =~ /~~iterate(\d)_open(_max(\d+))?~~/
+                for iter in iterations.values
+                    if iter['open']
+                        iter['open'] = false
+                        iter['close_wait'] = $1.to_i
+                    end
+                end
+                iterations[$1.to_i] = { 'open' => true, 'max' => $3, 'opening' => '', 'closing' => '' }
+                if $1.to_i == 1
+                    i.sub!(/.*/, '~~thumbnails~~')
+                else
+                    i.sub!(/.*/, '')
+                end
+            elsif i =~ /~~iterate(\d)_close~~/
+                iterations[$1.to_i]['open']  = false;
+                iterations[$1.to_i]['close'] = true;
+                i.sub!(/.*/, '')
+            else
+                for iter in iterations.values
+                    if iter['open']
+                        iter['opening'] += i
+                        i.sub!(/.*/, '')
+                    end
+                    if !iter['close'] && iter['close_wait'] && iterations[iter['close_wait']]['close']
+                        iter['closing'] += i
+                        i.sub!(/.*/, '')
+                    end
+                end
             end
+        end
+        html_thumbnails = ''
+        for iter in iterations.values
+            iter['value'] = 1
+        end
+        thumbnail_images.each_index { |index|
+            for level in iterations.keys.sort
+                if iterations[level]['value'] == 1 || level == iterations.keys.max
+                    html_thumbnails += iterations[level]['opening']
+                end
+                iterations[level]['value'] += 1
+                if iterations[level]['max'] && iterations[level]['value'] > iterations[level]['max'].to_i
+                    iterations[level]['value'] = 1
+                    iterations[level-1]['value'] = 1
+                    html_thumbnails += iterations[level-1]['closing']
+                end
+            end
+            html_thumbnails.sub!(/~~image_iteration~~/,
+                                 '<a href="image.html?current=' + fullscreen_images[index] + '"><img src="' + thumbnail_images[index] + '" border="0"/></a>')
+            html_thumbnails.sub!(/~~caption_iteration~~/,
+                                 $captions[images[index]] || File.basename(images[index]))
         }
+        for level in iterations.keys.sort.reverse
+            html_thumbnails += iterations[level]['closing']
+        end
+        for i in html
+            i.sub!(/~~thumbnails~~/, html_thumbnails)
+        end
+        ios = File.open("#{dest_dir}/index.html", "w")
+        ios.write(html)
+        ios.close
 
-        html = $skeleton.collect { |l| l.clone }
-        images4js = final_images.collect { |e| "\"#{e}\"" }.join(', ')
+        #- image.html (page with fullscreen images)
+        html = $html_images.collect { |l| l.clone }
+        images4js = fullscreen_images.collect { |e| "\"#{e}\"" }.join(', ')
         captions4js = find_captions(images).collect { |e| "\"#{e}\"" }.join(', ')
         for i in html
             i.sub!(/~~images~~/, images4js)
             i.sub!(/~~captions~~/, captions4js)
             i.sub!(/~~title~~/, File.basename(dir))
         end
-
-        ios = File.open("#{dest_dir}/index.html", "w")
+        ios = File.open("#{dest_dir}/image.html", "w")
         ios.write(html)
         ios.close
     }
@@ -296,6 +377,6 @@ end
 handle_options
 check_installation
 
-$skeleton = build_html_skeleton
+build_html_skeletons
 
 walk_source_dir
index 3f9f8abf187717fb4633c1ed4c9c5d81a7db2767..2bade8c2e999295a18d6b2c58b965cdf7b4fbd1e 100644 (file)
@@ -39,6 +39,7 @@ $images_size = [
     {
         'name' => 'large',
         'explanation' => { 'en' => 'Large (for 1280x1024 screens)' },
-        'size' => '880x704'
+        'size' => '880x704',
+        'thumbnails' => '300x240',
     }
 ]
index 2be00d04b11e1653645d153862861118477a26fd..3a3c0df857d1a5ca7e0be96a2f096ffb35040da2 100644 (file)
@@ -20,6 +20,7 @@
     <td width="1%">~~~button_last~~~</td>
     <td width="10%"></td>
 </tr>
+<!-- <p id="dbg_text">&nbsp;</p> -->
 <tr>
     <td align="center" colspan="9">
         ~~~image~~~
diff --git a/themes/simple/skeleton_thumbnails.html b/themes/simple/skeleton_thumbnails.html
new file mode 100644 (file)
index 0000000..672b744
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<head>
+    <title>~~title~~</title>
+    ~~~head_code~~~
+</head>
+
+<body bgcolor="#FFFFFF" ~~~body_additions~~~>
+
+<p align="center"><font size="+3">~~title~~</font></p>
+
+<p align="center"><a href="image.html?run_slideshow">~~run_slideshow~~</a></p>
+
+<table width="100%">
+~~iterate1_open~~
+<tr>
+    ~~iterate2_open_max4~~
+    <td width="25%">
+       ~~image_iteration~~
+       <p align="center">~~caption_iteration~~</p>
+    </td>
+    ~~iterate2_close~~
+</tr>
+~~iterate1_close~~
+</table>
+
+</body>
+</html>