libis-format 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6fcaac952f46961bb147aa74701c93116b9e62a33924c82c1c39e939e6fa8f5
|
4
|
+
data.tar.gz: 184bcd3c2ea39d8b0303bec9d68908bc33f2c3b9dd8872506f9b6e89cb57c618
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abe4e81ed1e79777a0c6319f9b3105965bdcef05fffd18d1da93dd14b147271846f544b914b04b246dd2f884eb48909c0bd8d6ae88768dbfef6db5b5d5d37f5b
|
7
|
+
data.tar.gz: c52f3d3d0ca1b55c984321b4b92cd9f93835ebbfce5ae68ee96d2e545f6ca501aa355719b5394eedb23cfe78db21f6c938b51926860a9db2845407fc11900d6e
|
@@ -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
|
-
# -
|
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
|
-
#
|
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
|
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
|
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("#{
|
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("#{
|
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 *
|
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("#{
|
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[:
|
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
|
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 [
|
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.
|
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
|
109
|
-
|
110
|
-
|
111
|
-
|
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],
|
252
|
+
@options[:watermark_opacity], watermark_position_filter)
|
218
253
|
elsif @options[:watermark_text]
|
219
|
-
@options[:
|
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=%
|
224
|
-
|
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])
|
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[:
|
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
|
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=#{
|
316
|
+
"x=#{margin_x}:y=H-#{h}-#{margin_y}"
|
270
317
|
when 'top_left'
|
271
|
-
"x=#{
|
318
|
+
"x=#{margin_x}:y=#{margin_y}"
|
272
319
|
when 'bottom_right'
|
273
|
-
"x=W-#{w}-#{
|
320
|
+
"x=W-#{w}-#{margin_x}:y=H-#{h}-#{margin_y}"
|
274
321
|
when 'top_right'
|
275
|
-
"x=W-#{w}-#{
|
322
|
+
"x=W-#{w}-#{margin_x}:y=#{margin_y}"
|
276
323
|
else
|
277
|
-
"x=#{
|
324
|
+
"x=#{margin_x}:y=H-#{h}-#{margin_y}"
|
278
325
|
end
|
279
326
|
end
|
280
327
|
end
|
data/lib/libis/format/version.rb
CHANGED
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
|
+
version: 1.3.5
|
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-
|
11
|
+
date: 2024-11-28 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.
|
370
|
+
rubygems_version: 3.5.22
|
371
371
|
signing_key:
|
372
372
|
specification_version: 4
|
373
373
|
summary: LIBIS File format format services.
|