counter = 0
pagecount = 0
reset_iterations(iterations)
+ #- preprocess the @filename->elem, rexml is very slow with that; we dramatically improve this part of the processing
+ optfilename = {}
+ xmldir.elements.each('image') { |elem|
+ optfilename[elem.attributes['filename']] = elem
+ }
for file in entries
type = images.include?(file) ? 'image' : videos.include?(file) ? 'video' : nil
if type
- if type == 'image' && elem = xmldir.elements["image[@filename='#{utf8(file)}']"]
+ if type == 'image' && elem = optfilename[utf8(file)]
if pano = pano_amount(elem)
html_elem = run_iterations(iterations, pano)
counter += count = pano.ceil
img_element("#{dest_dir}/#{thumbnail_images[sizeobj['name']][index]}") + '</a>')
html_thumbnails_nojs.gsub!(/~~image_iteration~~/,
'<a href="' + fullscreen_images[sizeobj['name']][index] + '" name="' + fullscreen_images[sizeobj['name']][index] + '">' +
- img_element("#{dest_dir}/#{thumbnail_images[sizeobj['name']][index]}") + '</a>')
+ img_element("#{dest_dir}/#{thumbnail_images[sizeobj['name']][index]}") + '</a>')
#- remember in which thumbnails page is this element, for image->thumbnail link
if sizeobj == $images_size[0]
image2thumbnailpage4js << pagecount
ios.close
#- substitute multiple "return to albums", previous/next correctly
+ #- the following two statements are dramatical optimizations to executing for each substInFile callback
+ dirpresent = xmldir.elements['dir']
+ parentname = xmldir.parent.name
if xmldir.child_byname_notattr('image', 'deleted') || xmldir.child_byname_notattr('video', 'deleted')
for suffix in [ '', '-nojs' ]
for sizeobj in $images_size
Dir.glob("#{dest_dir}/thumbnails-#{size2js(sizeobj['name'])}#{suffix}-*.html") do |file|
substInFile(file) { |line|
sub_previous_next_album(previous_album, next_album, line)
- if xmldir.elements['dir']
+ if dirpresent
line.sub!(/~~return_to_albums~~/, '<a href="index.html">' + utf8(_('return to albums')) + '</a>')
else
- if xmldir.parent.name == 'dir'
+ if parentname == 'dir'
line.sub!(/~~return_to_albums~~/, '<a href="../index.html">' + utf8(_('return to albums')) + '</a>')
else
line.sub!(/~~return_to_albums~~/, '')
require 'booh/config.rb'
require 'booh/version.rb'
+begin
+ require 'gtk2'
+rescue LoadError
+ $no_gtk2 = true
+end
module Booh
$verbose_level = 2
end
def get_image_size(fullpath)
- if !$no_identify && `identify '#{fullpath}'` =~ / JPEG (\d+)x(\d+) /
- return { :x => $1.to_i, :y => $2.to_i }
+ if !$no_identify
+ if $sizes_cache.nil?
+ $sizes_cache = {}
+ end
+ if $sizes_cache[fullpath].nil?
+ #- identify is slow, try with gdk if available (4ms 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 }
+ end
+ end
+ end
+ return $sizes_cache[fullpath]
else
return nil
end