Module: Imogen
- Extended by:
- FFI::Library
- Defined in:
- lib/imogen.rb,
lib/imogen/dzi.rb,
lib/imogen/iiif.rb,
lib/imogen/zoomable.rb,
lib/imogen/auto_crop.rb,
lib/imogen/iiif/size.rb,
lib/imogen/iiif/tiles.rb,
lib/imogen/iiif/region.rb,
lib/imogen/iiif/rotation.rb
Defined Under Namespace
Modules: AutoCrop, Cropped, Dzi, Iiif, Scaled, Zoomable
Class Method Summary
collapse
Class Method Details
.find_lib(lib) ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/imogen.rb', line 45
def self.find_lib(lib)
files = search_paths.inject(Array.new) do |array, path|
file_name = File.expand_path(File.join(path, "#{lib}.#{FFI::Platform::LIBSUFFIX}"))
array << Dir.glob(file_name)
array
end
files.flatten.compact.first
end
|
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/imogen.rb', line 76
def self.format_from(image_path)
result = FreeImage.FreeImage_GetFileType(image_path, 0)
FreeImage.check_last_error
if result == :unknown
result = FreeImage.FreeImage_GetFIFFromFilename(image_path)
FreeImage.check_last_error
end
result
end
|
.free_image_library_paths ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'lib/imogen.rb', line 54
def self.free_image_library_paths
@free_image_library_paths ||= begin
libs = %w{libfreeimage libfreeimage.3 FreeImage}
libs.map do |lib|
find_lib(lib)
end.compact
end
end
|
.from(src_path) ⇒ Object
7
8
9
10
11
|
# File 'lib/imogen.rb', line 7
def self.from(src_path)
FreeImage::Bitmap.open(src_path) do |img|
yield img
end
end
|
.image(src_path, flags = 0) ⇒ Object
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/imogen.rb', line 88
def self.image(src_path, flags=0)
fif = format_from(src_path)
if ((fif != :unknown) and FreeImage.FreeImage_FIFSupportsReading(fif))
ptr = FreeImage.FreeImage_Load(fif, src_path, flags)
FreeImage.check_last_error(ptr)
return FreeImage::Bitmap.new(ptr, nil)
end
return nil
end
|
.search_paths ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/imogen.rb', line 33
def self.search_paths
@search_paths ||= begin
if ENV['FREE_IMAGE_LIBRARY_PATH']
[ ENV['FREE_IMAGE_LIBRARY_PATH'] ]
elsif FFI::Platform::IS_WINDOWS
ENV['PATH'].split(File::PATH_SEPARATOR)
else
[ '/usr/local/{lib64,lib32,lib}', '/opt/local/{lib64,lib32,lib}', '/usr/{lib64,lib32,lib}' ]
end
end
end
|
.with_image(src_path, flags = 0, &block) ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'lib/imogen.rb', line 98
def self.with_image(src_path, flags = 0, &block)
fif = format_from(src_path)
if ((fif != :unknown) and FreeImage.FreeImage_FIFSupportsReading(fif))
ptr = FreeImage.FreeImage_Load(fif, src_path, flags)
FreeImage.check_last_error(ptr)
FreeImage::Bitmap.new(ptr, nil, &block)
end
end
|