Class: Libis::Format::Converter::ImageWatermarker
- Defined in:
- lib/libis/format/converter/image_watermarker.rb
Overview
noinspection RubyTooManyInstanceVariablesInspection
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#composition(v) ⇒ Object
the image composition method for merging the watermark image default ‘modulate’ See imagemagick.org/script/compose.php for more information.
-
#composition_args(v) ⇒ Object
arguments for the composition method default ‘10’ See imagemagick.org/script/compose.php for more information.
- #convert(source, target, format, opts = {}) ⇒ Object
-
#file(v) ⇒ Object
watermark image to use.
-
#gap(v) ⇒ Object
size of the gap between watermark instances.
-
#gravity(v) ⇒ Object
center point for the watermark overlay default ‘center’.
- #image_watermark(_) ⇒ Object
-
#initialize ⇒ ImageWatermarker
constructor
A new instance of ImageWatermarker.
- #page(v) ⇒ Object
- #quiet(v) ⇒ Object
-
#resize(v) ⇒ Object
fraction 0.0 - 1.0.
-
#rotation(v) ⇒ Object
rotation of the watermark text (counter clockwise in degrees; integer number) default 30.
-
#text(v) ⇒ Object
text to create a watermark from.
-
#tiles(v) ⇒ Object
number of tiles of the watermark default 4 0: no tiling, so only 1 watermark will be placed with the original size 1: 1 tile, so the watermark will be scaled up to fill the image n > 1: minimum n tiles in both directions n < 0: tile without scaling the watermark.
Methods inherited from Base
category, #check_file_exist, inherited, using_temp, #using_temp
Constructor Details
#initialize ⇒ ImageWatermarker
Returns a new instance of ImageWatermarker.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 39 def initialize super @quiet = true @wm_image = nil @wm_file = nil @wm_text = '© LIBIS' @wm_tiles = 4 @wm_resize = nil @wm_gap = 20 @wm_gravity = 'Center' @wm_rotation = 30 @wm_composition ='modulate' @wm_composition_args = '10' end |
Class Method Details
.input_types ⇒ Object
26 27 28 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 26 def self.input_types [:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF, :JP2] end |
.multipage?(format) ⇒ Boolean
35 36 37 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 35 def self.multipage?(format) [:PDF, :TIFF, :GIF, :PBM, :PGM, :PPM].include?(format) end |
.output_types(format = nil) ⇒ Object
30 31 32 33 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 30 def self.output_types(format = nil) return [] unless input_types.include?(format) if format [format] end |
Instance Method Details
#composition(v) ⇒ Object
the image composition method for merging the watermark image default ‘modulate’ See imagemagick.org/script/compose.php for more information
122 123 124 125 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 122 def composition(v) @wm_composition = v.blank? ? nil : v self end |
#composition_args(v) ⇒ Object
arguments for the composition method default ‘10’ See imagemagick.org/script/compose.php for more information
130 131 132 133 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 130 def composition_args(v) @wm_composition_args = v.blank? ? nil : v self end |
#convert(source, target, format, opts = {}) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 136 def convert(source, target, format, opts = {}) super FileUtils.mkpath(File.dirname(target)) if source.is_a?(Array) || File.directory?(source) error 'Only a single image file is allowed for input' else image = MiniMagick::Image.open(source) { |b| b.quiet } if image.pages.size > 1 if @page convert_image(image.pages[@page].path, target, format) else error 'multipage input file detecte; you need to supply a page number' end else convert_image(source, target, format) end end target end |
#file(v) ⇒ Object
watermark image to use
70 71 72 73 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 70 def file(v) @wm_file = v.blank? ? nil : v self end |
#gap(v) ⇒ Object
size of the gap between watermark instances. Fractions as percentage of widht/height default 0.2
107 108 109 110 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 107 def gap(v) @wm_gap = (v.to_f * 100).to_i self end |
#gravity(v) ⇒ Object
center point for the watermark overlay default ‘center’
114 115 116 117 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 114 def gravity(v) @wm_gravity = v.blank? ? nil : v self end |
#image_watermark(_) ⇒ Object
54 55 56 57 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 54 def image_watermark(_) #force usage of this converter self end |
#page(v) ⇒ Object
64 65 66 67 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 64 def page(v) @page = v.to_i self end |
#quiet(v) ⇒ Object
59 60 61 62 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 59 def quiet(v) @quiet = !!v self end |
#resize(v) ⇒ Object
fraction 0.0 - 1.0
100 101 102 103 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 100 def resize(v) @wm_resize = (v.to_f * 100).to_i self end |
#rotation(v) ⇒ Object
rotation of the watermark text (counter clockwise in degrees; integer number) default 30
83 84 85 86 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 83 def rotation(v) @wm_rotation = v.to_i self end |
#text(v) ⇒ Object
text to create a watermark from
76 77 78 79 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 76 def text(v) @wm_text = v.blank? ? nil : v self end |
#tiles(v) ⇒ Object
number of tiles of the watermark default 4 0: no tiling, so only 1 watermark will be placed with the original size 1: 1 tile, so the watermark will be scaled up to fill the image n > 1: minimum n tiles in both directions n < 0: tile without scaling the watermark
94 95 96 97 |
# File 'lib/libis/format/converter/image_watermarker.rb', line 94 def tiles(v) @wm_tiles = v.to_i self end |