From c6d5ae4835b98416a3e06692c057e902309224d5 Mon Sep 17 00:00:00 2001 From: gc Date: Sun, 8 Jul 2007 12:58:34 +0000 Subject: [PATCH] use Gdk::Pixbuf#get_file_info for obtaining the dimensions of the picture, its faaaster --- lib/booh/booh-lib.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/booh/booh-lib.rb b/lib/booh/booh-lib.rb index 50b45eb..086f8a7 100644 --- a/lib/booh/booh-lib.rb +++ b/lib/booh/booh-lib.rb @@ -227,14 +227,15 @@ module Booh $sizes_cache = {} end if $sizes_cache[fullpath].nil? - #- identify is slow, try with gdk if available (4ms vs 35ms) + #- identify is slow, try with gdk if available (negligible vs 35ms) if $no_gtk2 if `identify '#{fullpath}'` =~ / JPEG (\d+)x(\d+) / $sizes_cache[fullpath] = { :x => $1.to_i, :y => $2.to_i } end else - if pxb = Gdk::Pixbuf.new(fullpath) - $sizes_cache[fullpath] = { :x => pxb.width, :y => pxb.height } + format, width, height = Gdk::Pixbuf.get_file_info(fullpath) + if width + $sizes_cache[fullpath] = { :x => width, :y => height } end end end @@ -271,8 +272,9 @@ module Booh else return 0 end - size = get_image_size(filename) + #- remove rotate if image is obviously already in portrait (situation can come from gthumb) + size = get_image_size(filename) if size && size[:x] < size[:y] return 0 else @@ -283,7 +285,7 @@ module Booh def rotate_pixbuf(pixbuf, angle) return pixbuf.rotate(angle == 90 ? Gdk::Pixbuf::ROTATE_CLOCKWISE : angle == 180 ? Gdk::Pixbuf::ROTATE_UPSIDEDOWN : - angle == 270 ? Gdk::Pixbuf::ROTATE_COUNTERCLOCKWISE : + (angle == 270 || angle == -90) ? Gdk::Pixbuf::ROTATE_COUNTERCLOCKWISE : Gdk::Pixbuf::ROTATE_NONE) end -- 2.30.4