remove rotate if image is obviously already in portrait (situation can come from...
authorgc <gc>
Sat, 2 Apr 2005 18:22:11 +0000 (18:22 +0000)
committergc <gc>
Sat, 2 Apr 2005 18:22:11 +0000 (18:22 +0000)
bin/booh
lib/booh/booh-lib.rb

index dc6781391f2c41d60123629937894653989bd891..ba6ecb931818259f46e722f87c7c0f081d892b7b 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -270,7 +270,11 @@ def close_iterations(iterations)
 end
 
 def img_element(fullpath)
-    sizespec = `identify '#{fullpath}'` =~ / JPEG (\d+)x(\d+) / ? 'width="' + $1 + '" height="' + $2 + '"' : ''
+    if size = get_image_size(fullpath)
+        sizespec = 'width="${size[:x]}" height="${size[:y]}"'
+    else
+        sizespec = ''
+    end
     return '<img src="' + File.basename(fullpath) + '" ' + sizespec + ' border="0"/>'
 end
 
index 942d5fb0bc7ff08b20594b4ad6060c97e78274ff..1e750c4743a7aaeca91f57cfe0537bc051fdf95c 100644 (file)
@@ -137,6 +137,14 @@ module Booh
         end
     end
 
+    def get_image_size(fullpath)
+        if `identify '#{fullpath}'` =~ / JPEG (\d+)x(\d+) /
+            return { :x => $1, :y => $2 }
+        else
+            return nil
+        end
+    end
+
     def gen_thumbnails(orig, xmldir, allow_background, dests)
         if !dests.detect { |dest| !File.exists?(dest['filename']) } 
             return true
@@ -157,6 +165,11 @@ module Booh
                         rotate = '-90'
                     end
                     rotate ||= '0'
+                    #- remove rotate if image is obviously already in portrait (situation can come from gthumb)
+                    size = get_image_size(orig)
+                    if size && size[:x] < size[:y]
+                        rotate = '0'
+                    end
                     felem.add_attribute('rotate', rotate)
                 end
                 convert_options += "-rotate #{rotate} "