libis-format 1.0.7 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +32 -24
- data/README.md +2 -2
- data/base/Dockerfile +5 -3
- data/base/rework_path +5 -10
- data/lib/libis/format.rb +5 -2
- data/lib/libis/format/cli/convert.rb +4 -4
- data/lib/libis/format/config.rb +3 -1
- data/lib/libis/format/converter/audio_converter.rb +2 -36
- data/lib/libis/format/converter/base.rb +21 -8
- data/lib/libis/format/converter/chain.rb +3 -3
- data/lib/libis/format/converter/image_assembler.rb +82 -0
- data/lib/libis/format/converter/image_converter.rb +20 -138
- data/lib/libis/format/converter/image_splitter.rb +80 -0
- data/lib/libis/format/converter/image_watermarker.rb +261 -0
- data/lib/libis/format/converter/jp2_converter.rb +1 -1
- data/lib/libis/format/converter/office_converter.rb +2 -2
- data/lib/libis/format/converter/pdf_assembler.rb +66 -0
- data/lib/libis/format/converter/pdf_converter.rb +27 -85
- data/lib/libis/format/converter/pdf_optimizer.rb +70 -0
- data/lib/libis/format/converter/pdf_splitter.rb +65 -0
- data/lib/libis/format/converter/pdf_watermarker.rb +110 -0
- data/lib/libis/format/converter/spreadsheet_converter.rb +2 -2
- data/lib/libis/format/converter/video_converter.rb +1 -1
- data/lib/libis/format/identifier.rb +3 -3
- data/lib/libis/format/info.rb +27 -0
- data/lib/libis/format/library.rb +147 -0
- data/lib/libis/format/tool/extension_identification.rb +4 -4
- data/lib/libis/format/tool/identification_tool.rb +6 -6
- data/lib/libis/format/tool/spreadsheet_to_ods.rb +1 -0
- data/lib/libis/format/version.rb +1 -1
- data/lib/libis/format/yaml_loader.rb +71 -0
- data/libis-format.gemspec +2 -1
- data/tools/fop/fop.bat +75 -75
- data/tools/fop/fop.cmd +31 -31
- data/tools/fop/fop.js +341 -341
- data/tools/fop/lib/avalon-framework.NOTICE.TXT +11 -11
- data/tools/fop/lib/xml-apis.LICENSE-SAX.html +17 -17
- data/tools/fop/lib/xml-apis.LICENSE.DOM-documentation.html +74 -74
- data/tools/fop/lib/xml-apis.LICENSE.DOM-software.html +66 -66
- metadata +13 -6
- data/lib/libis/format/type_database.rb +0 -133
- data/lib/libis/format/type_database_impl.rb +0 -120
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f563ad694fd3d0c9e4a9f0da3309c99ac4b103e6027fcc9cda1606f0f67549c2
|
4
|
+
data.tar.gz: 5cee3f4b3bb1e51db492ee14bf919b0ce0fa69e267292380364c32b4eec40b4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 409ea1fac8f8be4d2519f189090207b6a550a1b1ce174a71fa1886c69b667001459d4bdccd850dd55373199ae5553ebd02183e15eebc88a73d0ac3f8093f7d12
|
7
|
+
data.tar.gz: d3e4d77ddcaab1f5050aaf4acb02e74a221566abedb94062254efbc24d18703c8fdd739644b1cd5435b54a4497e77c82bdcbcb218d121bfaf135e483662aca06
|
data/.travis.yml
CHANGED
@@ -1,41 +1,45 @@
|
|
1
|
+
dist: bionic
|
1
2
|
language: ruby
|
2
|
-
sudo: false
|
3
|
-
dist: trusty
|
4
3
|
cache: bundler
|
4
|
+
sudo: false
|
5
5
|
rvm:
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.
|
9
|
-
- 2.
|
6
|
+
- 2.3
|
7
|
+
- 2.4
|
8
|
+
- 2.5
|
9
|
+
- 2.6
|
10
10
|
- ruby-head
|
11
|
-
- jruby-9.
|
12
|
-
- jruby-9.
|
11
|
+
- jruby-9.1
|
12
|
+
- jruby-9.2
|
13
13
|
- jruby-head
|
14
14
|
jdk:
|
15
|
-
-
|
16
|
-
-
|
15
|
+
- openjdk10
|
16
|
+
- openjdk11
|
17
17
|
matrix:
|
18
18
|
exclude:
|
19
|
-
- rvm: 2.
|
20
|
-
jdk:
|
21
|
-
- rvm: 2.
|
22
|
-
jdk:
|
23
|
-
- rvm: 2.
|
24
|
-
jdk:
|
25
|
-
- rvm: 2.
|
26
|
-
jdk:
|
19
|
+
- rvm: 2.3
|
20
|
+
jdk: openjdk10
|
21
|
+
- rvm: 2.4
|
22
|
+
jdk: openjdk10
|
23
|
+
- rvm: 2.5
|
24
|
+
jdk: openjdk10
|
25
|
+
- rvm: 2.6
|
26
|
+
jdk: openjdk10
|
27
27
|
- rvm: ruby-head
|
28
|
-
jdk:
|
28
|
+
jdk: openjdk10
|
29
29
|
allow_failures:
|
30
30
|
- rvm: ruby-head
|
31
31
|
- rvm: jruby-head
|
32
32
|
branches:
|
33
33
|
only:
|
34
|
-
|
34
|
+
- master
|
35
|
+
- v2
|
35
36
|
before_install:
|
36
|
-
-
|
37
|
+
- gem update --system
|
38
|
+
- gem --version
|
39
|
+
- sudo add-apt-repository ppa:mc3man/bionic-media -y
|
37
40
|
- sudo apt-get update -y -q
|
38
|
-
- sudo apt-get install
|
41
|
+
- sudo apt-get install
|
42
|
+
- sudo apt-get install -y -q ffmpeg ubuntu-restricted-extras
|
39
43
|
- sudo pip install --upgrade pip
|
40
44
|
- sudo pip install --upgrade --ignore-installed opf-fido six
|
41
45
|
- sudo wget -O droid.zip -q http://www.nationalarchives.gov.uk/documents/information-management/droid-binary-6.4-bin.zip
|
@@ -43,8 +47,12 @@ before_install:
|
|
43
47
|
- sudo unzip droid.zip -d /opt/droid
|
44
48
|
- sudo chmod 755 /opt/droid/droid.sh
|
45
49
|
- sudo locale-gen "en_US.UTF-8"
|
46
|
-
- sudo
|
47
|
-
-
|
50
|
+
- echo 'Europe/Brussels' | sudo tee /etc/timezone
|
51
|
+
- export TZ=Europe/Brussels
|
52
|
+
- sudo dpkg-reconfigure --frontend noninteractive tzdata
|
53
|
+
- date
|
54
|
+
before_script:
|
55
|
+
- export TZ=Europe/Brussels
|
48
56
|
env:
|
49
57
|
- LC_ALL=en_US.UTF-8
|
50
58
|
- LANG=en_US.UTF-8
|
data/README.md
CHANGED
@@ -26,9 +26,9 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
### ::Libis::Format::
|
29
|
+
### ::Libis::Format::Library
|
30
30
|
|
31
|
-
The
|
31
|
+
The format database is the core of the format services. It stores information about all the known formats.
|
32
32
|
|
33
33
|
### ::Libis::Format::Identifier
|
34
34
|
|
data/base/Dockerfile
CHANGED
@@ -27,7 +27,9 @@ RUN wget -q -O fop.tar.gz "http://www.apache.org/dyn/closer.cgi?filename=/xmlgra
|
|
27
27
|
&& rm fop.tar.gz
|
28
28
|
|
29
29
|
RUN echo "8\n9\n" | apt-get install tzdata
|
30
|
-
|
31
|
-
ADD ./
|
32
|
-
ADD ./
|
30
|
+
RUN mkdir -p /teneo/format/spec
|
31
|
+
ADD ./tools /teneo/format/tools
|
32
|
+
ADD ./data /teneo/format/data
|
33
|
+
ADD ./spec/data /teneo/format/spec/data
|
34
|
+
ADD ./base/rework_path /teneo/format/rework_path
|
33
35
|
CMD /bin/bash
|
data/base/rework_path
CHANGED
@@ -1,25 +1,20 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
-
#file=${1/$SRC_PATH/$TGT_PATH}
|
4
|
-
#echo "$1 -> $file"
|
5
|
-
|
6
3
|
CMD=$1
|
7
4
|
shift
|
8
5
|
|
9
6
|
readarray -d ',' -t mapping <<< "$VOLUME_MAPPING"
|
10
7
|
|
11
8
|
args=("$@")
|
12
|
-
echo "args: ${args[@]}"
|
13
|
-
#args="${args[@]/$SRC_PATH/$TGT_PATH}"
|
14
|
-
#args="${args[@]/$SRC_TMP/$TGT_TMP}"
|
9
|
+
#echo "args: ${args[@]}"
|
15
10
|
for map in "${mapping[@]}"
|
16
11
|
do
|
17
12
|
map="${map//[$'\t\r\n ']}"
|
18
13
|
readarray -d '=' -t m <<< "$map"
|
19
14
|
src="${m[0]//[$'\t\r\n ']}"
|
20
15
|
tgt="${m[1]//[$'\t\r\n ']}"
|
21
|
-
echo "$src -> $tgt"
|
22
|
-
args="${args[@]/$src/$tgt}"
|
23
|
-
echo "args: ${args[@]}"
|
16
|
+
# echo "$src -> $tgt"
|
17
|
+
args=("${args[@]/$src/$tgt}")
|
18
|
+
# echo "args: ${args[@]}"
|
24
19
|
done
|
25
|
-
|
20
|
+
${CMD} "${args[@]}"
|
data/lib/libis/format.rb
CHANGED
@@ -3,8 +3,11 @@ require 'libis/format/version'
|
|
3
3
|
module Libis
|
4
4
|
module Format
|
5
5
|
autoload :Config, 'libis/format/config'
|
6
|
-
|
7
|
-
autoload :
|
6
|
+
|
7
|
+
autoload :Info, 'libis/format/info'
|
8
|
+
autoload :Library, 'libis/format/library'
|
9
|
+
autoload :YamlLoader, 'libis/format/yaml_loader'
|
10
|
+
|
8
11
|
autoload :Identifier, 'libis/format/identifier'
|
9
12
|
|
10
13
|
autoload :Tool, 'libis/format/tool'
|
@@ -67,7 +67,7 @@ module Libis
|
|
67
67
|
arguments that any of the targetted converters support.
|
68
68
|
|
69
69
|
The source file's format will be identified by the Libis::Format::Identifier and the target file's format
|
70
|
-
will be derived from the file's extension. The Libis::Format::
|
70
|
+
will be derived from the file's extension. The Libis::Format::Library is used to relate extensions
|
71
71
|
with formats.
|
72
72
|
|
73
73
|
DESC
|
@@ -89,7 +89,7 @@ module Libis
|
|
89
89
|
A source file name and target file name should be supplied. The source file should exist and be readable.
|
90
90
|
The target file should be writable, but should not exist.
|
91
91
|
|
92
|
-
The target file's format will be derived from the file's extension. The Libis::Format::
|
92
|
+
The target file's format will be derived from the file's extension. The Libis::Format::Library is used
|
93
93
|
to relate extensions with formats.
|
94
94
|
|
95
95
|
DESC
|
@@ -265,11 +265,11 @@ module Libis
|
|
265
265
|
end
|
266
266
|
|
267
267
|
def extname(format)
|
268
|
-
Libis::Format::
|
268
|
+
Libis::Format::Library.get_field(format, :extensions)
|
269
269
|
end
|
270
270
|
|
271
271
|
def get_format(file_name)
|
272
|
-
Libis::Format::
|
272
|
+
Libis::Format::Library.get_field_by(:extension, File.extname(file_name), :format)
|
273
273
|
end
|
274
274
|
|
275
275
|
def format_identifier(file)
|
data/lib/libis/format/config.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'os'
|
3
|
+
require 'libis-tools'
|
3
4
|
|
4
5
|
module Libis
|
5
6
|
module Format
|
@@ -23,7 +24,8 @@ module Libis
|
|
23
24
|
Config[:preflight_jar] = File.join(Libis::Format::TOOL_DIR, 'pdfbox', 'preflight-app-2.0.13.jar')
|
24
25
|
# noinspection RubyStringKeysInHashInspection
|
25
26
|
Config[:xml_validations] = [['archive/ead', File.join(Libis::Format::DATA_DIR, 'ead.xsd')]]
|
26
|
-
Config[:
|
27
|
+
Config[:format_library_implementation] = 'Libis::Format::YamlLoader.instance'
|
28
|
+
Config[:format_library_database] = File.join(Libis::Format::DATA_DIR, 'types.yml')
|
27
29
|
Config[:raw_audio_convert_cmd] = 'sox -V1 %s -e signed -b 16 -t wav %s rate %d channels %d'
|
28
30
|
Config[:watermark_font] = '/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf'
|
29
31
|
Config[:timeouts] = {
|
@@ -15,7 +15,7 @@ module Libis
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.output_types(format = nil)
|
18
|
-
return [] unless input_types.include?(format)
|
18
|
+
return [] unless format.nil? || input_types.include?(format)
|
19
19
|
[:MP3, :FLAC, :AC3, :AAC, :WMA, :ALAC, :WAV, :AIFF, :AMR, :AU, :M4A]
|
20
20
|
end
|
21
21
|
|
@@ -69,47 +69,13 @@ module Libis
|
|
69
69
|
(@options[:preset] ||= {})[stream] = name
|
70
70
|
end
|
71
71
|
|
72
|
-
# def encoder(value)
|
73
|
-
# @options[:encoder] = value
|
74
|
-
# end
|
75
|
-
#
|
76
|
-
# def encoder_options(value)
|
77
|
-
# @options[:encoder_options] = value
|
78
|
-
# end
|
79
|
-
|
80
72
|
def convert(source, target, _format, opts = {})
|
81
73
|
super
|
82
74
|
|
83
75
|
FileUtils.mkpath(File.dirname(target))
|
84
76
|
|
85
|
-
|
86
|
-
|
87
|
-
assemble_and_convert(source, target)
|
88
|
-
|
89
|
-
elsif File.directory?(source)
|
90
|
-
|
91
|
-
sources = Dir[File.join(source, '**', '*')].reject {|p| File.directory? p}
|
92
|
-
assemble_and_convert(sources, target)
|
77
|
+
convert_file(source, target)
|
93
78
|
|
94
|
-
else
|
95
|
-
|
96
|
-
convert_file(source, target)
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
target
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
def assemble_and_convert(sources, target)
|
105
|
-
Tempfile.create(%w(list .txt)) do |f|
|
106
|
-
sources.each {|src| f.puts src}
|
107
|
-
opts[:global] ||= []
|
108
|
-
opts[:global] += %w(-f concat)
|
109
|
-
f.close
|
110
|
-
target = convert_file(f.to_path, target)
|
111
|
-
end
|
112
|
-
target
|
113
79
|
end
|
114
80
|
|
115
81
|
def self.sounds_like(file1, file2, threshold, rate, channels)
|
@@ -4,7 +4,7 @@
|
|
4
4
|
require 'tmpdir'
|
5
5
|
require 'libis/tools/logger'
|
6
6
|
require 'libis/tools/temp_file'
|
7
|
-
require 'libis/format/
|
7
|
+
require 'libis/format/library'
|
8
8
|
|
9
9
|
require_relative 'repository'
|
10
10
|
|
@@ -22,10 +22,23 @@ module Libis
|
|
22
22
|
@flags = {}
|
23
23
|
end
|
24
24
|
|
25
|
+
def self.category
|
26
|
+
:converter
|
27
|
+
end
|
28
|
+
|
29
|
+
def check_file_exist(file)
|
30
|
+
unless File.exist? file
|
31
|
+
error "Cannot find file '#{file}'."
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
25
37
|
def convert(source, target, format, opts = {})
|
26
|
-
|
27
|
-
|
28
|
-
|
38
|
+
if source.is_a?(Array)
|
39
|
+
return nil unless source.map { |f| check_file_exist(f) }.reduce(:&)
|
40
|
+
else
|
41
|
+
return nil unless check_file_exist(source)
|
29
42
|
end
|
30
43
|
@options.merge!(opts[:options]) if opts[:options]
|
31
44
|
@flags.merge!(opts[:flags]) if opts[:flags]
|
@@ -51,7 +64,7 @@ module Libis
|
|
51
64
|
target
|
52
65
|
end
|
53
66
|
|
54
|
-
def Base.inherited(
|
67
|
+
def Base.inherited(klass)
|
55
68
|
|
56
69
|
Repository.register klass
|
57
70
|
|
@@ -73,12 +86,12 @@ module Libis
|
|
73
86
|
end
|
74
87
|
|
75
88
|
def input_mimetype?(mimetype)
|
76
|
-
type_id =
|
89
|
+
type_id = Libis::Format::Library.get_field_by(:mimetype, mimetype, :format)
|
77
90
|
input_type? type_id
|
78
91
|
end
|
79
92
|
|
80
93
|
def output_mimetype?(mimetype)
|
81
|
-
type_id =
|
94
|
+
type_id = Libis::Format::Library.get_field_by(:mimetype, mimetype, :format)
|
82
95
|
output_type? type_id
|
83
96
|
end
|
84
97
|
|
@@ -91,7 +104,7 @@ module Libis
|
|
91
104
|
end
|
92
105
|
|
93
106
|
def extension?(extension)
|
94
|
-
!
|
107
|
+
!Libis::Format::Library.get_field_by(:extension, extension, :format).nil?
|
95
108
|
end
|
96
109
|
|
97
110
|
end
|
@@ -5,7 +5,7 @@ require 'deep_dive'
|
|
5
5
|
|
6
6
|
require 'libis/tools/logger'
|
7
7
|
require 'libis/tools/extend/hash'
|
8
|
-
require 'libis/format/
|
8
|
+
require 'libis/format/library'
|
9
9
|
|
10
10
|
module Libis
|
11
11
|
module Format
|
@@ -83,8 +83,8 @@ module Libis
|
|
83
83
|
target = target_file
|
84
84
|
|
85
85
|
if i < size - 1
|
86
|
-
target += ".temp.#{
|
87
|
-
target += ".#{
|
86
|
+
target += ".temp.#{Libis::Format::Library.get_field(target_type, :extensions).first}"
|
87
|
+
target += ".#{Libis::Format::Library.get_field(target_type, :extensions).first}" while File.exist? target
|
88
88
|
temp_files << target
|
89
89
|
end
|
90
90
|
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
require 'libis/format/identifier'
|
5
|
+
|
6
|
+
require 'mini_magick'
|
7
|
+
|
8
|
+
MiniMagick.logger.level = ::Logger::UNKNOWN
|
9
|
+
|
10
|
+
MiniMagick.configure do |config|
|
11
|
+
# config.cli = :graphicsmagick
|
12
|
+
config.validate_on_create = false
|
13
|
+
config.validate_on_write = false
|
14
|
+
config.whiny = false
|
15
|
+
end
|
16
|
+
|
17
|
+
module Libis
|
18
|
+
module Format
|
19
|
+
module Converter
|
20
|
+
|
21
|
+
# noinspection RubyTooManyInstanceVariablesInspection,DuplicatedCode
|
22
|
+
class ImageAssembler < Libis::Format::Converter::Base
|
23
|
+
|
24
|
+
def self.input_types
|
25
|
+
[:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF, :JP2]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.output_types(format = nil)
|
29
|
+
return [] unless input_types.include?(format) if format
|
30
|
+
[:PDF, :TIFF, :GIF, :PBM, :PGM, :PPM]
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.category
|
34
|
+
:assembler
|
35
|
+
end
|
36
|
+
|
37
|
+
def image_assemble(_)
|
38
|
+
#force usage of this converter
|
39
|
+
end
|
40
|
+
|
41
|
+
def quiet(v)
|
42
|
+
@quiet = !!v
|
43
|
+
end
|
44
|
+
|
45
|
+
def convert(source, target, format, opts = {})
|
46
|
+
super
|
47
|
+
|
48
|
+
FileUtils.mkpath(File.dirname(target))
|
49
|
+
|
50
|
+
if source.is_a? Array
|
51
|
+
assemble(source, target, format)
|
52
|
+
elsif File.directory?(source)
|
53
|
+
source_list = Dir[File.join(source, '**', '*')].reject {|p| File.directory? p}
|
54
|
+
assemble(source_list, target, format)
|
55
|
+
else
|
56
|
+
image = MiniMagick::Image.open(source) {|b| b.quiet}
|
57
|
+
if image.pages.size > 1
|
58
|
+
assemble(image.pages.map {|page| page.path}, target, format)
|
59
|
+
else
|
60
|
+
assemble([source], target, format)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
target
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def assemble(sources, target, format)
|
71
|
+
MiniMagick::Tool::Convert.new do |b|
|
72
|
+
sources.each {|source| b << source}
|
73
|
+
convert.format(format)
|
74
|
+
b << target
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -4,7 +4,6 @@ require_relative 'base'
|
|
4
4
|
require 'libis/format/identifier'
|
5
5
|
|
6
6
|
require 'mini_magick'
|
7
|
-
require 'fileutils'
|
8
7
|
|
9
8
|
MiniMagick.logger.level = ::Logger::UNKNOWN
|
10
9
|
|
@@ -23,11 +22,11 @@ module Libis
|
|
23
22
|
class ImageConverter < Libis::Format::Converter::Base
|
24
23
|
|
25
24
|
def self.input_types
|
26
|
-
[:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF, :JP2]
|
25
|
+
[:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF, :JP2, :PBM, :PGM, :PPM]
|
27
26
|
end
|
28
27
|
|
29
28
|
def self.output_types(format = nil)
|
30
|
-
return [] unless input_types.include?(format)
|
29
|
+
return [] unless input_types.include?(format) if format
|
31
30
|
[:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF, :JP2]
|
32
31
|
end
|
33
32
|
|
@@ -46,109 +45,57 @@ module Libis
|
|
46
45
|
|
47
46
|
def quiet(v)
|
48
47
|
@quiet = !!v
|
48
|
+
self
|
49
49
|
end
|
50
50
|
|
51
51
|
def page(nr)
|
52
52
|
@page = nr
|
53
|
+
self
|
53
54
|
end
|
54
55
|
|
55
56
|
def scale(percent)
|
56
57
|
@options[:scale] = percent
|
58
|
+
self
|
57
59
|
end
|
58
60
|
|
59
61
|
def resize(geometry)
|
60
62
|
@options[:resize] = geometry
|
63
|
+
self
|
61
64
|
end
|
62
65
|
|
63
66
|
def quality(value)
|
64
67
|
@options[:quality] = value
|
68
|
+
self
|
65
69
|
end
|
66
70
|
|
67
71
|
def dpi(value)
|
68
72
|
@options[:density] = value
|
73
|
+
self
|
69
74
|
end
|
70
75
|
|
71
76
|
def resample(value)
|
72
77
|
@options[:resample] = value
|
78
|
+
self
|
73
79
|
end
|
74
80
|
|
75
81
|
def flatten(value = true)
|
76
|
-
@options[:flatten] =
|
82
|
+
@options[:flatten] = value
|
83
|
+
self
|
77
84
|
end
|
78
85
|
|
79
86
|
def colorspace(value)
|
80
87
|
@options[:colorspace] = value
|
88
|
+
self
|
81
89
|
end
|
82
90
|
|
83
91
|
def delete_date(value = true)
|
84
|
-
@delete_date =
|
92
|
+
@delete_date = value
|
93
|
+
self
|
85
94
|
end
|
86
95
|
|
87
96
|
def profile(icc)
|
88
97
|
@profile = icc
|
89
|
-
|
90
|
-
|
91
|
-
# Create or use a watermark image.
|
92
|
-
#
|
93
|
-
# The watermark options are:
|
94
|
-
# - file: watermark image to use
|
95
|
-
# - text: text to create a watermark from
|
96
|
-
# - rotation: rotation of the watermark text (counter clockwise in degrees; integer number) - default 30
|
97
|
-
# - tiles: number of tiles of the watermark - default 4
|
98
|
-
# - 0: no tiling, so only 1 watermark will be placed with the original size
|
99
|
-
# - 1: 1 tile, so the watermark will be scaled up to fill the image
|
100
|
-
# - n > 1: minimum n tiles in both directions
|
101
|
-
# - n < 0: tile without scaling the watermark
|
102
|
-
# - size: same as tiles - for backwards compatibility
|
103
|
-
# - resize: fraction 0.0 - 1.0
|
104
|
-
# - gap: size of the gap between watermark instances. Fractions as percentage of widht/height. - default 0.2
|
105
|
-
# - opacity: opacity of the watermark (fraction 0.0 - 1.0) - default 0.1
|
106
|
-
# - gravity: center point of the overlay - default 'center'
|
107
|
-
# If both options are given, the file will be used as-is if it exists and is a valid image file. Otherwise the
|
108
|
-
# file will be created or overwritten with a newly created watermark image.
|
109
|
-
#
|
110
|
-
# The created watermark file will be a PNG image with transparent background containing the supplied text
|
111
|
-
# slanted by 30 degrees counter-clockwise.
|
112
|
-
#
|
113
|
-
# @param [Hash] options Hash of options for watermark creation.
|
114
|
-
def watermark(options = {})
|
115
|
-
text = options[:text] || '© LIBIS'
|
116
|
-
@wm_tiles = (options[:tiles] || '4').to_i
|
117
|
-
@wm_tiles ||= (options[:size] || '4').to_i
|
118
|
-
@wm_resize = ((options[:resize]).to_f * 100).to_i if options[:resize]
|
119
|
-
@wm_opacity = ((options[:opacity] || 0.1).to_f * 100).to_i
|
120
|
-
@wm_composition = options[:composition] || 'modulate'
|
121
|
-
@wm_gravity = options[:gravity] || 'center'
|
122
|
-
@wm_gap = ((options[:gap] || 0.2).to_f * 100).to_i
|
123
|
-
rotation = 360 - (options[:rotation] || 30).to_i
|
124
|
-
@wm_image = MiniMagick::Image.new(options[:file]) if options[:file]
|
125
|
-
unless @wm_image && @wm_image.valid?
|
126
|
-
image = options[:file] || (Dir::Tmpname.create(%w(wm_image .png)) {|_|})
|
127
|
-
# noinspection RubyResolve
|
128
|
-
MiniMagick::Tool::Convert.new do |convert|
|
129
|
-
# noinspection RubyLiteralArrayInspection
|
130
|
-
convert.quiet
|
131
|
-
convert.background 'transparent'
|
132
|
-
convert.size('2000x2000')
|
133
|
-
convert.gravity 'Center'
|
134
|
-
convert.font('Helvetica').fill('black').pointsize(72) #.stroke('black').strokewidth(1)
|
135
|
-
convert << "label:#{text}"
|
136
|
-
convert.rotate rotation
|
137
|
-
convert.trim.repage.+
|
138
|
-
convert << image
|
139
|
-
end
|
140
|
-
if options[:file]
|
141
|
-
@wm_image = MiniMagick::Image.new(image)
|
142
|
-
else
|
143
|
-
@wm_image = MiniMagick::Image.open(image)
|
144
|
-
File.delete(image)
|
145
|
-
end
|
146
|
-
# noinspection RubyResolve
|
147
|
-
unless @wm_image.valid?
|
148
|
-
error "Problem creating watermark image '#{image}'."
|
149
|
-
@wm_image = nil
|
150
|
-
end
|
151
|
-
end
|
98
|
+
self
|
152
99
|
end
|
153
100
|
|
154
101
|
def convert(source, target, format, opts = {})
|
@@ -156,90 +103,25 @@ module Libis
|
|
156
103
|
|
157
104
|
FileUtils.mkpath(File.dirname(target))
|
158
105
|
|
159
|
-
|
160
|
-
|
161
|
-
assemble_and_convert(source, target, format)
|
162
|
-
|
163
|
-
elsif File.directory?(source)
|
164
|
-
source_list = Dir[File.join(source, '**', '*')].reject {|p| File.directory? p}
|
165
|
-
|
166
|
-
assemble_and_convert(source_list, target, format)
|
167
|
-
|
168
|
-
else
|
169
|
-
|
170
|
-
image = MiniMagick::Image.open(source) { |b| b.quiet }
|
171
|
-
|
172
|
-
if image.pages.size > 1
|
173
|
-
if @page
|
174
|
-
convert_image(image.pages[@page].path, target, format)
|
175
|
-
else
|
176
|
-
# noinspection RubyBlockToMethodReference
|
177
|
-
assemble_and_convert(image.pages.map {|page| page.path}, target, format)
|
178
|
-
end
|
179
|
-
else
|
180
|
-
convert_image(source, target, format)
|
181
|
-
end
|
182
|
-
end
|
106
|
+
convert_image(source, target, format)
|
183
107
|
|
184
108
|
target
|
185
109
|
|
186
110
|
end
|
187
111
|
|
188
|
-
def assemble_and_convert(sources, target, format)
|
189
|
-
|
190
|
-
warn 'Received multiple images as input and single page format as target.' unless self.class.multipage?(format)
|
191
|
-
converted_pages = sources.inject([]) do |list, path|
|
192
|
-
# noinspection RubyArgCount
|
193
|
-
converted = Tempfile.new(['page-', ".#{Libis::Format::TypeDatabase.type_extentions(format).first}"])
|
194
|
-
convert_image(path, converted.path, format)
|
195
|
-
list << converted
|
196
|
-
end
|
197
|
-
MiniMagick::Tool::Convert.new do |b|
|
198
|
-
b.append unless self.class.multipage?(format)
|
199
|
-
converted_pages.each {|page| b << page.path}
|
200
|
-
b << target
|
201
|
-
end
|
202
|
-
converted_pages.each do |temp_file|
|
203
|
-
temp_file.close
|
204
|
-
temp_file.unlink
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
112
|
protected
|
209
113
|
|
210
114
|
def convert_image(source, target, format)
|
211
115
|
|
212
|
-
|
213
|
-
|
116
|
+
if @page
|
117
|
+
image = MiniMagick::Image.open(source) { |b| b.quiet }
|
118
|
+
source = image.pages[@page].path if image.pages.size > 1
|
119
|
+
end
|
214
120
|
|
215
121
|
MiniMagick::Tool::Convert.new do |convert|
|
216
|
-
convert.quiet if @quiet
|
217
|
-
if @wm_image
|
218
|
-
convert << @wm_image.path
|
219
|
-
convert.bordercolor('transparent').border("#{@wm_gap}%") if @wm_gap > 0
|
220
|
-
convert.filter('Lagrange')
|
221
|
-
convert.resize("#{image_info['width'] / @wm_tiles}x#{image_info['height'] / @wm_tiles}") if @wm_tiles > 0
|
222
|
-
convert.resize("#{@wm_resize}%") if @wm_resize
|
223
|
-
convert.write('mpr:watermark').delete.+
|
224
|
-
end
|
225
|
-
|
226
122
|
convert.quiet if @quiet
|
227
123
|
convert << source
|
228
124
|
convert.flatten if @options[:flatten].nil? && format == :JPG
|
229
|
-
if @wm_image
|
230
|
-
if @wm_tiles >= 0 and @wm_tiles <= 1
|
231
|
-
convert << 'mpr:watermark'
|
232
|
-
else
|
233
|
-
convert.stack do |stack|
|
234
|
-
stack.size("#{image_info['width']}x#{image_info['height']}")
|
235
|
-
stack << 'xc:transparent'
|
236
|
-
stack.tile('mpr:watermark')
|
237
|
-
stack.draw "rectangle 0,0,#{image_info['width']},#{image_info['height']}"
|
238
|
-
end
|
239
|
-
end
|
240
|
-
convert.compose(@wm_composition).gravity(@wm_gravity).define("compose:args=#{@wm_opacity}%").composite
|
241
|
-
end
|
242
|
-
|
243
125
|
@flags.each {|f, v| v.is_a?(TrueClass) ? convert.send(f).+ : convert.send(f)}
|
244
126
|
if @delete_date
|
245
127
|
convert << '+set' << 'modify-date' << '+set' << 'create-date'
|