Class: ImageProcessing::Vips::Processor
Defined Under Namespace
Modules: Utils
Constant Summary
collapse
- SHARPEN_MASK =
default sharpening mask that provides a fast and mild sharpen
::Vips::Image.new_from_array [[-1, -1, -1],
[-1, 32, -1],
[-1, -1, -1]], 24
Class Method Summary
collapse
Instance Method Summary
collapse
-
#composite(other, mode, **options) ⇒ Object
-
#resize_and_pad(width, height, gravity: "centre", extend: nil, background: nil, alpha: nil, **options) ⇒ Object
-
#resize_to_fill(width, height, **options) ⇒ Object
-
#resize_to_fit(width, height, **options) ⇒ Object
-
#resize_to_limit(width, height, **options) ⇒ Object
-
#rotate(degrees, background: nil) ⇒ Object
-
#set(*args) ⇒ Object
make Vips::Image#set, #set_type, and #set_value chainable.
-
#set_type(*args) ⇒ Object
-
#set_value(*args) ⇒ Object
Methods inherited from Processor
accumulator, apply_operation, #custom, #initialize
Class Method Details
.load_image(path_or_image, autorot: true, **options) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/image_processing/vips.rb', line 26
def self.load_image(path_or_image, autorot: true, **options)
if path_or_image.is_a?(::Vips::Image)
image = path_or_image
else
source_path = path_or_image
options = Utils.select_valid_loader_options(source_path, options)
image = ::Vips::Image.new_from_file(source_path, **options)
end
image = image.autorot if autorot && !options.key?(:autorotate)
image
end
|
.save_image(image, destination_path, quality: nil, **options) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/image_processing/vips.rb', line 40
def self.save_image(image, destination_path, quality: nil, **options)
options = options.merge(Q: quality) if quality
options = Utils.select_valid_saver_options(destination_path, options)
image.write_to_file(destination_path, **options)
end
|
Instance Method Details
#composite(other, mode, **options) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/image_processing/vips.rb', line 81
def composite(other, mode, **options)
other = [other] unless other.is_a?(Array)
other = other.map do |object|
if object.is_a?(String)
::Vips::Image.new_from_file(object)
elsif object.respond_to?(:to_path)
::Vips::Image.new_from_file(object.to_path)
elsif object.respond_to?(:path)
::Vips::Image.new_from_file(object.path)
else
object
end
end
image.composite(other, mode, **options)
end
|
#resize_and_pad(width, height, gravity: "centre", extend: nil, background: nil, alpha: nil, **options) ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'lib/image_processing/vips.rb', line 61
def resize_and_pad(width, height, gravity: "centre", extend: nil, background: nil, alpha: nil, **options)
embed_options = { extend: extend, background: background }
embed_options.reject! { |name, value| value.nil? }
image = thumbnail(width, height, **options)
image = image.add_alpha if alpha && !image.has_alpha?
image.gravity(gravity, width, height, **embed_options)
end
|
#resize_to_fill(width, height, **options) ⇒ Object
57
58
59
|
# File 'lib/image_processing/vips.rb', line 57
def resize_to_fill(width, height, **options)
thumbnail(width, height, crop: :centre, **options)
end
|
#resize_to_fit(width, height, **options) ⇒ Object
52
53
54
55
|
# File 'lib/image_processing/vips.rb', line 52
def resize_to_fit(width, height, **options)
width, height = default_dimensions(width, height)
thumbnail(width, height, **options)
end
|
#resize_to_limit(width, height, **options) ⇒ Object
47
48
49
50
|
# File 'lib/image_processing/vips.rb', line 47
def resize_to_limit(width, height, **options)
width, height = default_dimensions(width, height)
thumbnail(width, height, size: :down, **options)
end
|
#rotate(degrees, background: nil) ⇒ Object
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/image_processing/vips.rb', line 70
def rotate(degrees, background: nil)
if degrees % 90 == 0
image.rot(:"d#{degrees % 360}")
else
options = { angle: degrees }
options[:background] = background if background
image.similarity(**options)
end
end
|
#set(*args) ⇒ Object
make Vips::Image#set, #set_type, and #set_value chainable
100
|
# File 'lib/image_processing/vips.rb', line 100
def set(*args) image.tap { |img| img.set(*args) } end
|
#set_type(*args) ⇒ Object
101
|
# File 'lib/image_processing/vips.rb', line 101
def set_type(*args) image.tap { |img| img.set_type(*args) } end
|
#set_value(*args) ⇒ Object
102
|
# File 'lib/image_processing/vips.rb', line 102
def set_value(*args) image.tap { |img| img.set_value(*args) } end
|