add width= and height= to img elements so that browser can place
authorgc <gc>
Tue, 15 Mar 2005 22:19:06 +0000 (22:19 +0000)
committergc <gc>
Tue, 15 Mar 2005 22:19:06 +0000 (22:19 +0000)
graphical elements at correct place immediately

booh

diff --git a/booh b/booh
index b7ed445202dc76a8f6c77c406b92d4bd983bef84..f9ff560c3e29f04eaac1927067419f9b483ff4ee 100755 (executable)
--- a/booh
+++ b/booh
@@ -199,7 +199,7 @@ def check_installation
     if $no_check
         return
     end
-    %w(convert exif transcode mencoder).each { |prg|
+    %w(convert identify exif transcode mencoder).each { |prg|
         if !system("which #{prg} >/dev/null")
             die __("The `%s' program is typically needed. Re-run with --no-check if you're sure you're fine without it.", prg)
         end
@@ -411,6 +411,11 @@ def close_iterations(iterations)
     return html
 end
 
+def img_element(fullpath)
+    sizespec = `identify #{fullpath}` =~ / JPEG (\d+)x(\d+) / ? 'width="' + $1 + '" height="' + $2 + '"' : ''
+    return '<img src="' + File.basename(fullpath) + '" ' + sizespec + ' border="0"/>'
+end
+
 def walk_source_dir
 
     `find #{$source} -type d`.each { |dir|
@@ -565,7 +570,7 @@ def walk_source_dir
                         index = images.index(file)
                         html_thumbnails.gsub!(/~~image_iteration~~/,
                                               '<a href="image-' + sizeobj['name'] + '.html?current=' + fullscreen_images[sizeobj['name']][index] + '">' +
-                                                  '<img src="' + thumbnail_images[sizeobj['name']][index] + '" border="0"/></a>')
+                                                  img_element("#{dest_dir}/#{thumbnail_images[sizeobj['name']][index]}") + '</a>')
                         html_thumbnails.gsub!(/~~caption_iteration~~/,
                                               find_caption_value(xmldir, images[index]) || images[index])
                         html_thumbnails.gsub!(/~~ifimage\?~~([^~]+)~~/) { $1 }
@@ -574,7 +579,7 @@ def walk_source_dir
                         index = videos.index(file)
                         if File.exists?("#{dest_dir}/#{thumbnail_videos[sizeobj['name']][index]}")
                             html_thumbnails.gsub!(/~~image_iteration~~/,
-                                                  '<a href="' + videos[index] + '"><img src="' + thumbnail_videos[sizeobj['name']][index] + '" border="0"/></a>')
+                                                  '<a href="' + videos[index] + '">' + img_element("#{dest_dir}/#{thumbnail_videos[sizeobj['name']][index]}") + '</a>')
                         else
                             html_thumbnails.gsub!(/~~image_iteration~~/,
                                                   '<a href="' + videos[index] + '">' + utf8(_("(no preview)")) + '</a>')
@@ -702,7 +707,7 @@ def walk_source_dir
                 thumbnail = "#{dest_dir}/thumbnails-thumbnail.jpg"
                 gen_thumbnails(xmldir.attributes['thumbnails-captionfile'], [ { 'filename' => thumbnail, 'size' => $albums_thumbnail_size } ])
                 html_index += run_iterations(iterations)
-                html_index.gsub!(/~~image_iteration~~/, "<a href='thumbnails-#{default_thumbnails}.html'><img src='#{File.basename(thumbnail)}' border='0'/></a>")
+                html_index.gsub!(/~~image_iteration~~/, "<a href='thumbnails-#{default_thumbnails}.html'>" + img_element(thumbnail) + '</a>')
                 html_index.gsub!(/~~caption_iteration~~/, xmldir.attributes['thumbnails-caption'])
             end
 
@@ -711,7 +716,7 @@ def walk_source_dir
                 subdir = File.basename(child.attributes['path'])
                 thumbnail = "#{dest_dir}/thumbnails-#{subdir}.jpg"
                 html_index += run_iterations(iterations)
-                html_index.gsub!(/~~image_iteration~~/, "<a href='#{subdir}/index.html'><img src='#{File.basename(thumbnail)}' border='0'/></a>")
+                html_index.gsub!(/~~image_iteration~~/, "<a href='#{subdir}/index.html'>" + img_element(thumbnail) + '</a>')
                 #- first look for subdirs info; if not, means there is no subdir
                 caption = child.attributes['subdirs-caption']
                 if caption