libis-format 1.3.4 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5fb1b156976a67b10d6885880a0611ba8361671c24da8014e7e11d7840be6318
4
- data.tar.gz: 1f5e6e9b1cd84031a5a1ae986a2d0de018bb021bb48d47d6d83c9feea1e8db59
3
+ metadata.gz: 3e25ef208425f644a2802a431cfde3e86538ffdd1c1f7599b3a9628e7c6d0a69
4
+ data.tar.gz: b1dc1523bfb969b84c2bd015ff672b9f3b35e73ac10a7019f8b05b80fbf767ec
5
5
  SHA512:
6
- metadata.gz: 364036443664fc6597d36456c554e25074926515c2b95c7475a93499a27389bc0a2d8749ba86f5cb29e47b50c41902780518b780abde202f0d69f2e3a550cf24
7
- data.tar.gz: b7d5823c3da6b25a71b2d7c3a2b05a9b15042e562985775b357490ccadabc457e0784136c1e269030f7211c94e3926a2000857efa03472cb9ca05f013f25128c
6
+ metadata.gz: c5822db02258ec2109d06ca1749a7555f5bd9508ae77d8d09b2c491e19d366387d79ddf4573f7e5ece6b01ab692325e265c81030161029c0561998091a0d49c0
7
+ data.tar.gz: fe8ad15bb3f0e97c7050995166452ab87897d3b4a7baf736c8dcba09ca1668d0145adc430acd771eaa2a082aa81e25052f8994eaaa6429edb512ef4e201591e6
@@ -10,14 +10,15 @@ module Libis
10
10
  module Format
11
11
  module Converter
12
12
  class EmailConverter < Libis::Format::Converter::Base
13
+
13
14
  def self.input_types
14
- [:MSG]
15
+ %i[MSG EML]
15
16
  end
16
17
 
17
18
  def self.output_types(format = nil)
18
19
  return [] unless input_types.include?(format)
19
20
 
20
- [:PDF]
21
+ %i[PDF]
21
22
  end
22
23
 
23
24
  def email_convert(_)
@@ -86,20 +86,13 @@ module Libis
86
86
 
87
87
  # Create or use a watermark image.
88
88
  #
89
- # The watermark options are (use symbols):
89
+ # The main watermark options are (use symbols):
90
90
  # - text: text to create a watermark from
91
91
  # - file: watermark image to use
92
92
  # - image: same as above
93
- # - rotation: rotation of the watermark text (in degrees; integer number)
94
- # - size: font size of the watermark text
95
- # - opacity: opacity of the watermark (fraction 0.0 - 1.0)
96
- # - gap: size of the gap between watermark instances. Integer value is absolute size in points (1/72 inch).
97
- # Fractions are percentage of widht/height.
98
- # If both options are given, the file will be used as-is if it exists and is a valid image file. Otherwise the
99
- # file will be created or overwritten with a newly created watermark image.
93
+ # - banner: use side banner
100
94
  #
101
- # The created watermark file will be a PNG image with transparent background containing the supplied text
102
- # slanted by 30 degrees counter-clockwise.
95
+ # For each of these options above a dedicated option handler will be called
103
96
  #
104
97
  # @param [Hash] options Hash of options for watermark creation.
105
98
 
@@ -169,13 +162,13 @@ module Libis
169
162
  @options[:watermark][:rotation] = 360 - (options[:rotation] || 30).to_i
170
163
  end
171
164
 
172
- # Create a vertical banner to the right side of each page
165
+ # Create a vertical banner to the right side of the image
173
166
  #
174
167
  # The banner options are:
175
168
  # - banner: text to put in the banner
176
169
  # - add_filename: append filename to the text (use any value to enable)
177
170
  # - fontsize: size of the font (in points) (default: autoscale)
178
- # - width: width of the banner (default: 3% of image height). Not including a border of 30% of the banner width
171
+ # - width: width of the banner (default: 3% of image height). Not including a border of 1/3 of the banner width
179
172
  # - background_color_(red|green|blue): color components of background (default: rgb(84,190,233))
180
173
  # - text_color_(red|green|blue): color components of background (default: rgb(255,255,255))
181
174
  def watermark_banner(options = {})
@@ -261,6 +254,8 @@ module Libis
261
254
  wm = @options.delete(:watermark)
262
255
  if wm
263
256
  image_info = MiniMagick::Image::Info.new(source) { |b| b.quiet }
257
+ im_height = image_info['height']
258
+ im_width = image_info['width']
264
259
  case wm[:command]
265
260
  when 'text'
266
261
  convert.background 'transparent'
@@ -272,7 +267,7 @@ module Libis
272
267
  convert.trim.repage.+ # rubocop:disable Lint/Void
273
268
  convert.bordercolor('transparent').border("#{wm[:gap]}%") if wm[:gap].positive?
274
269
  convert.filter('Lagrange')
275
- convert.resize("#{image_info['width'] / wm[:tiles]}x#{image_info['height'] / wm[:tiles]}") if wm[:tiles].positive?
270
+ convert.resize("#{im_width / wm[:tiles]}x#{im_height / wm[:tiles]}") if wm[:tiles].positive?
276
271
  convert.resize("#{wm[:resize]}%") if wm[:resize]
277
272
  when 'image'
278
273
  convert << wm[:data]
@@ -280,13 +275,13 @@ module Libis
280
275
  convert.bordercolor('transparent').border("#{wm[:gap]}%") if wm[:gap].positive?
281
276
  convert.rotate wm[:rotation]
282
277
  convert.filter('Lagrange')
283
- convert.resize("#{image_info['width'] / wm[:tiles]}x#{image_info['height'] / wm[:tiles]}") if wm[:tiles].positive?
278
+ convert.resize("#{im_width / wm[:tiles]}x#{im_height / wm[:tiles]}") if wm[:tiles].positive?
284
279
  convert.resize("#{wm[:resize]}%") if wm[:resize]
285
280
  when 'banner'
286
- banner_width = wm[:width] || [0.03 * image_info['height'], 20].max.round(0)
281
+ banner_width = wm[:width] || [0.03 * im_height, 20].max.round(0)
287
282
  banner_border = banner_width / 3
288
283
  convert.background "rgb(#{wm[:background_red]},#{wm[:background_green]},#{wm[:background_blue]})"
289
- convert.size("#{image_info['height']}x#{banner_width}")
284
+ convert.size("#{im_height}x#{banner_width}")
290
285
  convert.bordercolor "rgb(#{wm[:background_red]},#{wm[:background_green]},#{wm[:background_blue]})"
291
286
  convert.border "0x#{banner_border}"
292
287
  convert.fill "rgb(#{wm[:text_red]},#{wm[:text_green]},#{wm[:text_blue]})"
@@ -298,6 +293,9 @@ module Libis
298
293
 
299
294
  # Save watermark image to buffer
300
295
  convert.write('mpr:watermark').delete.+
296
+
297
+ # Restore canvas to source image size (workaround for IM bug when loading JP2K files)
298
+ convert.size("#{im_width}x#{im_height}")
301
299
  end
302
300
 
303
301
  # load source image
@@ -64,7 +64,7 @@ module Libis
64
64
  end
65
65
 
66
66
  def constant_rate_factor(value)
67
- @options[:crf] = value.to_s
67
+ @options[:constant_rate_factor] = value.to_s
68
68
  end
69
69
 
70
70
  def frame_rate(value)
@@ -84,36 +84,66 @@ module Libis
84
84
  @options[:watermark_image] = file
85
85
  end
86
86
 
87
- # @param [String] value text for watermark. No watermark if nil (default)
87
+ # @param [String] value Text for watermark. No watermark if nil (default)
88
88
  def watermark_text(value)
89
- @options[:watermark_text] = value
89
+ @options[:watermark_text] = value.to_s
90
90
  end
91
91
 
92
- # @param [Integer] value Font size for watermark text. Default: 10
92
+ # @param [Boolean] value Should the filename be appended to the watermark text; use any value to enable
93
+ def watermark_text_add_filename(value)
94
+ @options[:watermark_text_add_filename] = !!value
95
+ end
96
+
97
+ # @param [String] value Font size for watermark text. Default: 10
93
98
  # Note that the font is selected by the Config[:watermark_font] setting
94
99
  def watermark_text_size(value)
95
- @options[:watermark_text_size] = value.to_i
100
+ @options[:watermark_text_size] = value.to_s
96
101
  end
97
102
 
98
103
  # @param [String] value Text color for the watermark text. Default: white
99
104
  def watermark_text_color(value)
100
- @options[:watermark_text_color] = value
105
+ @options[:watermark_text_color] = value.to_s
106
+ end
107
+
108
+ # @param [Integer] value Offset of the watermark text shadow. Used for both x and y offset; default: 1
109
+ # If the offset is set to 0, no shadow will be printed
110
+ def watermark_text_shadow_offset(value)
111
+ @options[:watermark_text_shadow_offset] = value.to_i
101
112
  end
102
113
 
103
114
  # @param [String] value Text color for the watermark text shadow. Default: black
104
115
  def watermark_text_shadow_color(value)
105
- @options[:watermark_text_shadow_color] = value
116
+ @options[:watermark_text_shadow_color] = value.to_s
106
117
  end
107
118
 
108
- # @param [Integer] value Offset of the watermark text shadow. Used for both x and y offset; default: 1
109
- # If the offset is set to 0, no shadow will be printed
110
- def watermark_text_shadow_offset(value)
111
- @options[:watermark_text_offset] = value.to_i
119
+ # @param [Integer] value Enable/disable watermark text box. 1 to enanble, 0 to disable; default: 0
120
+ def watermark_text_box(value)
121
+ @options[:watermark_text_box] = value.to_i
122
+ end
123
+
124
+ # @param [String] value Color of the watermark text box; default: white
125
+ def watermark_text_box_color(value)
126
+ @options[:watermark_text_box_color] = value.to_s
127
+ end
128
+
129
+ # @param [String] value Border width of the watermark text box
130
+ def watermark_text_box_width(value)
131
+ @options[:watermark_text_box_width] = value.to_s
112
132
  end
113
133
 
114
134
  # @param [String] value one of 'bottom_left' (default), 'top_left', 'bottom_right', 'top_right', 'center'
115
135
  def watermark_position(value)
116
- @options[:watermark_position] = value
136
+ @options[:watermark_position] = value.to_s
137
+ end
138
+
139
+ # @param [String] value offset x value for the text box. Default: 10
140
+ def watermark_offset_x(value)
141
+ @options[:watermark_offset_x] = value.to_s
142
+ end
143
+
144
+ # @param [String] value offset y value for the text box. Default: 10
145
+ def watermark_offset_y(value)
146
+ @options[:watermark_offset_y] = value.to_s
117
147
  end
118
148
 
119
149
  # @param [Number] value watermark opacity (0-1) with 0 = invisible and 1 = 100% opaque. Default: 0.5
@@ -121,6 +151,11 @@ module Libis
121
151
  @options[:watermark_opacity] = value.to_f
122
152
  end
123
153
 
154
+ # @param [Number] value watermark blending (0-1) with 0 = invisible and 1 = 100% opaque. Default: 0.5
155
+ def watermark_blending(value)
156
+ @options[:watermark_blending] = value.to_f
157
+ end
158
+
124
159
  # @param [Boolean] value If set to true automatically selects optimal format for web viewing. Default: false
125
160
  def web_stream(value)
126
161
  return unless value
@@ -214,20 +249,30 @@ module Libis
214
249
  if @options[:watermark_image]
215
250
  opts[:filter] << '-i' << @options[:watermark_image] << '-filter_complex'
216
251
  opts[:filter] << Kernel.format('[1:v]format=argb,colorchannelmixer=aa=%f[wm];[0:v][wm]overlay=%s',
217
- @options[:watermark_opacity], watermark_position_text)
252
+ @options[:watermark_opacity], watermark_position_filter)
218
253
  elsif @options[:watermark_text]
219
- @options[:watermark_text_size] ||= 10
254
+ wm_text = @options[:watermark_text]
255
+ wm_text += File.basename(source, '.*') if @options[:watermark_text_add_filename]
256
+ @options[:watermark_text_size] ||= '10'
220
257
  @options[:watermark_text_color] ||= 'white'
221
258
  @options[:watermark_text_shadow_color] ||= 'black'
222
259
  @options[:watermark_text_shadow_offset] ||= 1
223
- filter_text = Kernel.format("drawtext=text='%s':%s:fontfile=%s:fontsize=%d:fontcolor=%s@%f",
224
- @options[:watermark_text], watermark_position_text(true), Config[:watermark_font],
260
+ filter_text = Kernel.format("drawtext=text='%s':%s:fontfile=%s:fontsize=%s:fontcolor=%s@%f",
261
+ wm_text, watermark_position_filter(true), Config[:watermark_font],
225
262
  @options[:watermark_text_size], @options[:watermark_text_color], @options[:watermark_opacity])
226
- if (@options[:watermark_text_shadow_offset]).positive?
263
+ if !(@options[:watermark_text_shadow_offset] == 0)
227
264
  filter_text += Kernel.format(':shadowcolor=%s@%f:shadowx=%d:shadowy=%d',
228
265
  @options[:watermark_text_shadow_color], @options[:watermark_opacity],
229
266
  @options[:watermark_text_shadow_offset], @options[:watermark_text_shadow_offset])
230
267
  end
268
+ @options[:watermark_text_box] ||= 0
269
+ if (@options[:watermark_text_box]).positive?
270
+ filter_text += Kernel.format(':box=1:boxcolor=%s:boxborderw=%s',
271
+ @options[:watermark_text_box_color], @options[:watermark_text_box_width])
272
+ end
273
+ if (@options[:watermark_blending])
274
+ filter_text += Kernel.format(':alpha=%f', @options[:watermark_blending])
275
+ end
231
276
  opts[:filter] << '-vf' << filter_text
232
277
  end
233
278
  opts[:output] << '-ac' << @options[:audio_channels] if @options[:audio_channels]
@@ -235,7 +280,7 @@ module Libis
235
280
  opts[:output] << '-c:v' << @options[:video_codec] if @options[:video_codec]
236
281
  opts[:output] << '-b:a' << @options[:audio_bitrate] if @options[:audio_bitrate]
237
282
  opts[:output] << '-b:v' << @options[:video_bitrate] if @options[:video_bitrate]
238
- opts[:output] << '-crf' << @options[:crf] if @options[:crf]
283
+ opts[:output] << '-crf' << @options[:constant_rate_factor] if @options[:constant_rate_factor]
239
284
  opts[:output] << '-map_metadata:g' << '0:g' # Copy global metadata
240
285
  opts[:output] << '-map_metadata:s:a' << '0:s:a' # Copy audio metadata
241
286
  opts[:output] << '-map_metadata:s:v' << '0:s:v' # Copy video metadata
@@ -261,20 +306,22 @@ module Libis
261
306
  target
262
307
  end
263
308
 
264
- def watermark_position_text(for_text = false, margin = 10)
309
+ def watermark_position_filter(for_text = false)
310
+ margin_x = @options[:watermark_offset_x] || 10
311
+ margin_y = @options[:watermark_offset_y] || 10
265
312
  w = for_text ? 'tw' : 'w'
266
313
  h = for_text ? 'th' : 'h'
267
314
  case @options[:watermark_position]
268
315
  when 'bottom_left'
269
- "x=#{margin}:y=H-#{h}-#{margin}"
316
+ "x=#{margin_x}:y=H-#{h}-#{margin_y}"
270
317
  when 'top_left'
271
- "x=#{margin}:y=#{margin}"
318
+ "x=#{margin_x}:y=#{margin_y}"
272
319
  when 'bottom_right'
273
- "x=W-#{w}-#{margin}:y=H-#{h}-#{margin}"
320
+ "x=W-#{w}-#{margin_x}:y=H-#{h}-#{margin_y}"
274
321
  when 'top_right'
275
- "x=W-#{w}-#{margin}:y=#{margin}"
322
+ "x=W-#{w}-#{margin_x}:y=#{margin_y}"
276
323
  else
277
- "x=#{margin}:y=H-#{h}-#{margin}"
324
+ "x=#{margin_x}:y=H-#{h}-#{margin_y}"
278
325
  end
279
326
  end
280
327
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Libis
4
4
  module Format
5
- VERSION = '1.3.4'
5
+ VERSION = '1.3.6'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libis-format
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Dekeyser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-11 00:00:00.000000000 Z
11
+ date: 2024-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chromaprint
@@ -367,7 +367,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
367
367
  - !ruby/object:Gem::Version
368
368
  version: '0'
369
369
  requirements: []
370
- rubygems_version: 3.5.18
370
+ rubygems_version: 3.4.19
371
371
  signing_key:
372
372
  specification_version: 4
373
373
  summary: LIBIS File format format services.