libis-format 0.9.41 → 0.9.44
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +365 -0
- data/bin/droid +1 -1
- data/bin/fido +1 -1
- data/bin/pdf_copy +1 -1
- data/lib/libis/format/config.rb +1 -0
- data/lib/libis/format/converter/audio_converter.rb +1 -1
- data/lib/libis/format/converter/base.rb +2 -1
- data/lib/libis/format/converter/office_converter.rb +2 -2
- data/lib/libis/format/converter/pdf_converter.rb +6 -6
- data/lib/libis/format/converter/video_converter.rb +96 -2
- data/lib/libis/format/identifier.rb +12 -12
- data/lib/libis/format/tool/droid.rb +108 -0
- data/lib/libis/format/tool/extension_identification.rb +58 -0
- data/lib/libis/format/tool/ffmpeg.rb +43 -0
- data/lib/libis/format/tool/fido.rb +91 -0
- data/lib/libis/format/tool/file_tool.rb +78 -0
- data/lib/libis/format/tool/identification_tool.rb +175 -0
- data/lib/libis/format/tool/office_to_pdf.rb +54 -0
- data/lib/libis/format/tool/pdf_copy.rb +42 -0
- data/lib/libis/format/tool/pdf_merge.rb +43 -0
- data/lib/libis/format/tool/pdf_optimizer.rb +38 -0
- data/lib/libis/format/tool/pdf_split.rb +41 -0
- data/lib/libis/format/tool/pdf_to_pdfa.rb +78 -0
- data/lib/libis/format/tool/pdfa_validator.rb +63 -0
- data/lib/libis/format/tool.rb +23 -0
- data/lib/libis/format/version.rb +1 -1
- data/lib/libis/format.rb +1 -15
- data/libis-format.gemspec +1 -2
- data/spec/converter_audio_spec.rb +66 -0
- data/spec/converter_image_spec.rb +166 -0
- data/spec/converter_office_spec.rb +84 -0
- data/spec/converter_pdf_spec.rb +30 -0
- data/spec/converter_repository_spec.rb +91 -0
- data/spec/converter_video_spec.rb +97 -0
- data/spec/data/video/copyright.png +0 -0
- data/spec/identifier_spec.rb +3 -15
- metadata +32 -33
- data/lib/libis/format/droid.rb +0 -106
- data/lib/libis/format/extension_identification.rb +0 -55
- data/lib/libis/format/ffmpeg.rb +0 -41
- data/lib/libis/format/fido.rb +0 -89
- data/lib/libis/format/file_tool.rb +0 -76
- data/lib/libis/format/identification_tool.rb +0 -174
- data/lib/libis/format/office_to_pdf.rb +0 -52
- data/lib/libis/format/pdf_copy.rb +0 -40
- data/lib/libis/format/pdf_merge.rb +0 -41
- data/lib/libis/format/pdf_optimizer.rb +0 -36
- data/lib/libis/format/pdf_split.rb +0 -39
- data/lib/libis/format/pdf_to_pdfa.rb +0 -74
- data/lib/libis/format/pdfa_validator.rb +0 -61
- data/spec/converter_spec.rb +0 -433
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'os'
|
2
|
+
|
3
|
+
require 'libis/tools/extend/string'
|
4
|
+
require 'libis/tools/logger'
|
5
|
+
require 'libis/tools/command'
|
6
|
+
|
7
|
+
require 'libis/format/config'
|
8
|
+
|
9
|
+
module Libis
|
10
|
+
module Format
|
11
|
+
module Tool
|
12
|
+
|
13
|
+
class PdfCopy
|
14
|
+
include ::Libis::Tools::Logger
|
15
|
+
|
16
|
+
def self.run(source, target, options = [])
|
17
|
+
self.new.run source, target, options
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(source, target, options = [])
|
21
|
+
tool_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'tools'))
|
22
|
+
jar_file = File.join(tool_dir, 'PdfTool.jar')
|
23
|
+
|
24
|
+
if OS.java?
|
25
|
+
# TODO: import library and execute in current VM. For now do exactly as in MRI.
|
26
|
+
end
|
27
|
+
|
28
|
+
Libis::Tools::Command.run(
|
29
|
+
Libis::Format::Config[:java_path],
|
30
|
+
'-cp', jar_file,
|
31
|
+
'CopyPdf',
|
32
|
+
'--file_input', source,
|
33
|
+
'--file_output', target,
|
34
|
+
*options
|
35
|
+
)
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'os'
|
2
|
+
|
3
|
+
require 'libis/tools/extend/string'
|
4
|
+
require 'libis/tools/logger'
|
5
|
+
require 'libis/tools/command'
|
6
|
+
|
7
|
+
require 'libis/format/config'
|
8
|
+
|
9
|
+
module Libis
|
10
|
+
module Format
|
11
|
+
module Tool
|
12
|
+
|
13
|
+
class PdfMerge
|
14
|
+
include ::Libis::Tools::Logger
|
15
|
+
|
16
|
+
def self.run(source, target, options = [])
|
17
|
+
self.new.run source, target, options
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(source, target, options = [])
|
21
|
+
tool_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'tools'))
|
22
|
+
jar_file = File.join(tool_dir, 'PdfTool.jar')
|
23
|
+
source = [source] unless source.is_a?(Array)
|
24
|
+
|
25
|
+
if OS.java?
|
26
|
+
# TODO: import library and execute in current VM. For now do exactly as in MRI.
|
27
|
+
end
|
28
|
+
|
29
|
+
Libis::Tools::Command.run(
|
30
|
+
Libis::Format::Config[:java_path],
|
31
|
+
'-cp', jar_file,
|
32
|
+
'MergePdf',
|
33
|
+
'--file_output', target,
|
34
|
+
*options,
|
35
|
+
*source,
|
36
|
+
)
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'os'
|
2
|
+
|
3
|
+
require 'libis/tools/extend/string'
|
4
|
+
require 'libis/tools/logger'
|
5
|
+
require 'libis/tools/command'
|
6
|
+
|
7
|
+
require 'libis/format/config'
|
8
|
+
|
9
|
+
module Libis
|
10
|
+
module Format
|
11
|
+
module Tool
|
12
|
+
|
13
|
+
class PdfOptimizer
|
14
|
+
include ::Libis::Tools::Logger
|
15
|
+
|
16
|
+
def self.run(source, target, quality)
|
17
|
+
self.new.run source, target, quality
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(source, target, quality)
|
21
|
+
|
22
|
+
Libis::Tools::Command.run(
|
23
|
+
'gs',
|
24
|
+
'-sDEVICE=pdfwrite',
|
25
|
+
'-dCompatibilityLevel=1.4',
|
26
|
+
"-dPDFSETTINGS=/#{quality}",
|
27
|
+
'-dNOPAUSE',
|
28
|
+
'-dBATCH',
|
29
|
+
"-sOutputFile=#{target}",
|
30
|
+
"#{source}"
|
31
|
+
)
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'os'
|
2
|
+
|
3
|
+
require 'libis/tools/extend/string'
|
4
|
+
require 'libis/tools/logger'
|
5
|
+
require 'libis/tools/command'
|
6
|
+
|
7
|
+
require 'libis/format/config'
|
8
|
+
|
9
|
+
module Libis
|
10
|
+
module Format
|
11
|
+
module Tool
|
12
|
+
|
13
|
+
class PdfSplit
|
14
|
+
include ::Libis::Tools::Logger
|
15
|
+
|
16
|
+
def self.run(source, target, options = [])
|
17
|
+
self.new.run source, target, options
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(source, target, options = [])
|
21
|
+
tool_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'tools'))
|
22
|
+
jar_file = File.join(tool_dir, 'PdfTool.jar')
|
23
|
+
if OS.java?
|
24
|
+
# TODO: import library and execute in current VM. For now do exactly as in MRI.
|
25
|
+
end
|
26
|
+
|
27
|
+
Libis::Tools::Command.run(
|
28
|
+
Libis::Format::Config[:java_path],
|
29
|
+
'-cp', jar_file,
|
30
|
+
'SplitPdf',
|
31
|
+
'--file_input', source,
|
32
|
+
'--file_output', target,
|
33
|
+
*options
|
34
|
+
)
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'csv'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
require 'libis/tools/extend/string'
|
6
|
+
require 'libis/tools/logger'
|
7
|
+
require 'libis/tools/command'
|
8
|
+
require 'libis/tools/temp_file'
|
9
|
+
|
10
|
+
require 'libis/format'
|
11
|
+
|
12
|
+
module Libis
|
13
|
+
module Format
|
14
|
+
module Tool
|
15
|
+
|
16
|
+
class PdfToPdfa
|
17
|
+
include ::Libis::Tools::Logger
|
18
|
+
|
19
|
+
def self.run(source, target = nil, options = {})
|
20
|
+
self.new.run source, target, options
|
21
|
+
end
|
22
|
+
|
23
|
+
def run(source, target = nil, options = nil)
|
24
|
+
|
25
|
+
tmp_target = Tools::TempFile.name(File.basename(source, '.*'), '.pdf')
|
26
|
+
target ||= tmp_target
|
27
|
+
|
28
|
+
icc_info = icc_options(options[:colorspace])
|
29
|
+
|
30
|
+
icc_file = Tools::TempFile.name(icc_info[:icc_name], '.icc')
|
31
|
+
FileUtils.cp(File.join(Libis::Format::DATA_DIR, "#{icc_info[:icc_name]}.icc"), icc_file)
|
32
|
+
|
33
|
+
def_filename = Tools::TempFile.name('PDFA_def', '.ps')
|
34
|
+
File.open(def_filename, 'w') do |f|
|
35
|
+
f.puts File.read(File.join(Libis::Format::DATA_DIR, 'PDFA_def.ps')).
|
36
|
+
gsub('[** Fill in ICC profile location **]', icc_file).
|
37
|
+
gsub('[** Fill in ICC reference name **]', icc_info[:icc_ref])
|
38
|
+
end
|
39
|
+
|
40
|
+
result = Libis::Tools::Command.run(
|
41
|
+
Libis::Format::Config[:ghostscript_path],
|
42
|
+
'-dBATCH', '-dNOPAUSE', '-dNOOUTERSAVE',
|
43
|
+
'-sColorConversionStrategy=/UseDeviceIndependentColor',
|
44
|
+
"-sProcessColorModel=#{icc_info[:device]}",
|
45
|
+
'-sDEVICE=pdfwrite', '-dPDFA', '-dPDFACompatibilityPolicy=1',
|
46
|
+
"-sOutputICCProfile=#{icc_file}",
|
47
|
+
'-o', File.absolute_path(target),
|
48
|
+
def_filename,
|
49
|
+
source
|
50
|
+
)
|
51
|
+
|
52
|
+
FileUtils.rm [icc_file, def_filename].compact, force: true
|
53
|
+
|
54
|
+
unless Format::Tool::PdfaValidator.run(target)
|
55
|
+
result[:status] = -999
|
56
|
+
result[:err] << 'Failed to validate generated PDF/A file.'
|
57
|
+
end
|
58
|
+
|
59
|
+
result
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def icc_options(colorspace)
|
66
|
+
case colorspace.to_s.downcase
|
67
|
+
when 'cmyk'
|
68
|
+
{icc_name: 'ISOcoated_v2_eci', icc_ref: 'FOGRA39L', device: 'DeviceCMYK'}
|
69
|
+
else
|
70
|
+
{icc_name: 'eciRGB_v2', icc_ref: 'sRGB', device: 'DeviceRGB'}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
require 'libis/tools/extend/string'
|
4
|
+
require 'libis/tools/logger'
|
5
|
+
require 'libis/tools/command'
|
6
|
+
|
7
|
+
require 'libis/format/config'
|
8
|
+
|
9
|
+
module Libis
|
10
|
+
module Format
|
11
|
+
module Tool
|
12
|
+
|
13
|
+
class PdfaValidator
|
14
|
+
include ::Libis::Tools::Logger
|
15
|
+
|
16
|
+
def self.run(source)
|
17
|
+
self.new.run source
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(source)
|
21
|
+
|
22
|
+
src_file = File.absolute_path(source)
|
23
|
+
|
24
|
+
if (pdfa = Libis::Format::Config[:pdfa_path])
|
25
|
+
# Keep it clean: tool generates fontconfig/ cache dir in current working dir
|
26
|
+
previous_wd = Dir.getwd
|
27
|
+
Dir.chdir(Dir.tmpdir)
|
28
|
+
|
29
|
+
result = Libis::Tools::Command.run(
|
30
|
+
pdfa,
|
31
|
+
'--noxml',
|
32
|
+
'--level', 'B',
|
33
|
+
'--verb', '0',
|
34
|
+
src_file
|
35
|
+
)
|
36
|
+
|
37
|
+
Dir.chdir(previous_wd)
|
38
|
+
|
39
|
+
unless result[:out].any? {|line| line =~ /^VLD-\[PASS\]/}
|
40
|
+
warn "Validator failed to validate the PDF file '%s' against PDF/A-1B constraints:\n%s", source,
|
41
|
+
result[:out].join("\n")
|
42
|
+
return false
|
43
|
+
end
|
44
|
+
else
|
45
|
+
jar = File.join(Libis::Format::ROOT_DIR, 'tools', 'pdfbox', 'preflight-app-1.8.10.jar')
|
46
|
+
result = Libis::Tools::Command.run(
|
47
|
+
Libis::Format::Config[:java_path],
|
48
|
+
'-jar', jar,
|
49
|
+
src_file
|
50
|
+
)
|
51
|
+
unless result[:status] == 0
|
52
|
+
warn "Validator failed to validate the PDF file '%s' against PDF/A-1B constraints:\n%s", source,
|
53
|
+
result[:out].join("\n")
|
54
|
+
return false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# code utf-8
|
2
|
+
|
3
|
+
module Libis
|
4
|
+
module Format
|
5
|
+
module Tool
|
6
|
+
|
7
|
+
autoload :Droid, 'libis/format/tool/droid'
|
8
|
+
autoload :ExtensionIdentification, 'libis/format/tool/extension_identification'
|
9
|
+
autoload :Fido, 'libis/format/tool/fido'
|
10
|
+
autoload :FileTool, 'libis/format/tool/file_tool'
|
11
|
+
|
12
|
+
autoload :OfficeToPdf, 'libis/format/tool/office_to_pdf'
|
13
|
+
autoload :FFMpeg, 'libis/format/tool/ffmpeg'
|
14
|
+
autoload :PdfCopy, 'libis/format/tool/pdf_copy'
|
15
|
+
autoload :PdfMerge, 'libis/format/tool/pdf_merge'
|
16
|
+
autoload :PdfOptimizer, 'libis/format/tool/pdf_optimizer'
|
17
|
+
autoload :PdfSplit, 'libis/format/tool/pdf_split'
|
18
|
+
autoload :PdfToPdfa, 'libis/format/tool/pdf_to_pdfa'
|
19
|
+
autoload :PdfaValidator, 'libis/format/tool/pdfa_validator'
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/libis/format/version.rb
CHANGED
data/lib/libis/format.rb
CHANGED
@@ -5,22 +5,8 @@ module Libis
|
|
5
5
|
autoload :Config, 'libis/format/config'
|
6
6
|
autoload :TypeDatabase, 'libis/format/type_database'
|
7
7
|
autoload :Identifier, 'libis/format/identifier'
|
8
|
-
autoload :Identifier, 'libis/format/identifier'
|
9
|
-
|
10
|
-
autoload :FileTool, 'libis/format/file_tool'
|
11
|
-
autoload :Fido, 'libis/format/fido'
|
12
|
-
autoload :Droid, 'libis/format/droid'
|
13
|
-
autoload :ExtensionIdentification, 'libis/format/extension_identification'
|
14
|
-
|
15
|
-
autoload :OfficeToPdf, 'libis/format/office_to_pdf'
|
16
|
-
autoload :PdfCopy, 'libis/format/pdf_copy'
|
17
|
-
autoload :PdfMerge, 'libis/format/pdf_merge'
|
18
|
-
autoload :PdfOptimizer, 'libis/format/pdf_optimizer'
|
19
|
-
autoload :PdfSplit, 'libis/format/pdf_split'
|
20
|
-
autoload :PdfToPdfa, 'libis/format/pdf_to_pdfa'
|
21
|
-
autoload :PdfaValidator, 'libis/format/pdfa_validator'
|
22
|
-
autoload :FFMpeg, 'libis/format/ffmpeg'
|
23
8
|
|
9
|
+
autoload :Tool, 'libis/format/tool'
|
24
10
|
autoload :Converter, 'libis/format/converter'
|
25
11
|
|
26
12
|
ROOT_DIR = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..'))
|
data/libis-format.gemspec
CHANGED
@@ -25,10 +25,9 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
26
26
|
spec.add_development_dependency 'rake', '~> 10.3'
|
27
27
|
spec.add_development_dependency 'rspec', '~> 3.1'
|
28
|
-
spec.add_development_dependency 'simplecov', '~> 0.9'
|
29
28
|
spec.add_development_dependency 'awesome_print'
|
30
29
|
|
31
|
-
spec.add_runtime_dependency 'libis-tools', '~> 0.9.
|
30
|
+
spec.add_runtime_dependency 'libis-tools', '~> 0.9.57'
|
32
31
|
spec.add_runtime_dependency 'os', '= 0.9.6'
|
33
32
|
spec.add_runtime_dependency 'mini_magick', '~> 4.3'
|
34
33
|
spec.add_runtime_dependency 'deep_dive', '~> 0.3'
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
require 'libis/format/converter/audio_converter'
|
5
|
+
|
6
|
+
describe 'Converters' do
|
7
|
+
|
8
|
+
let(:repository) {Libis::Format::Converter::Repository}
|
9
|
+
let(:file_dir) {File.dirname(__FILE__)}
|
10
|
+
|
11
|
+
before(:all) {
|
12
|
+
Libis::Tools::Config.logger.level = 'off'
|
13
|
+
}
|
14
|
+
|
15
|
+
context 'Audio Converter' do
|
16
|
+
|
17
|
+
let(:converter) {Libis::Format::Converter::AudioConverter.new}
|
18
|
+
extensions = %w'aac aiff au flac m4a mka mp3 ra voc wav wma'
|
19
|
+
confidence = {
|
20
|
+
aac: 0.86,
|
21
|
+
aiff: 0.99,
|
22
|
+
au: 0.99,
|
23
|
+
flac: 0.99,
|
24
|
+
m4a: 0.93,
|
25
|
+
mka: 0.94,
|
26
|
+
mp3: 0.95,
|
27
|
+
ra: 0.92,
|
28
|
+
voc: 0.99,
|
29
|
+
wav: 0.99,
|
30
|
+
wma: 0.9
|
31
|
+
}
|
32
|
+
targets = %w'mp3 flac wav'
|
33
|
+
sources = %w'carlin_disappointed greensleeves king_nonviolence top_gun_secret'
|
34
|
+
quality = {
|
35
|
+
carlin_disappointed: 1.0,
|
36
|
+
greensleeves: 0.95,
|
37
|
+
king_nonviolence: 1.0,
|
38
|
+
top_gun_secret: 0.95
|
39
|
+
}
|
40
|
+
|
41
|
+
let(:data_dir) {File.join(file_dir, 'data', 'audio')}
|
42
|
+
|
43
|
+
context 'converts' do
|
44
|
+
sources.each do |source|
|
45
|
+
extensions.each do |ext|
|
46
|
+
next unless (File.exists?(File.join(File.dirname(__FILE__), 'data', 'audio', "#{source}.#{ext}")))
|
47
|
+
(targets - [ext]).each do |tgt|
|
48
|
+
it "#{source} #{ext} to #{tgt}" do
|
49
|
+
src_file = File.join(data_dir, "#{source}.#{ext}")
|
50
|
+
ref_file = File.join(data_dir, "#{source}.#{tgt}")
|
51
|
+
tgt_file = File.join('', 'tmp', "test.#{source}.#{ext}.#{tgt}")
|
52
|
+
FileUtils.remove tgt_file, force: true
|
53
|
+
FileUtils.mkdir_p File.dirname(tgt_file)
|
54
|
+
result = converter.convert(src_file, tgt_file, tgt.upcase.to_sym)
|
55
|
+
expect(result).to eq tgt_file
|
56
|
+
expect(result).to sound_like ref_file, confidence[ext.to_sym] * quality[source.to_sym], 11025, 1
|
57
|
+
FileUtils.remove tgt_file, force: true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
require 'libis/format/converter/image_converter'
|
5
|
+
require 'libis/format/converter/jp2_converter'
|
6
|
+
|
7
|
+
describe 'Converters' do
|
8
|
+
|
9
|
+
let(:repository) {Libis::Format::Converter::Repository}
|
10
|
+
let(:file_dir) {File.dirname(__FILE__)}
|
11
|
+
|
12
|
+
before(:all) {
|
13
|
+
Libis::Tools::Config.logger.level = 'off'
|
14
|
+
}
|
15
|
+
|
16
|
+
context 'Image Converter' do
|
17
|
+
|
18
|
+
let(:converter) {Libis::Format::Converter::ImageConverter.new}
|
19
|
+
let(:diff_file) {File.join('', 'tmp', 'diff.jpg')}
|
20
|
+
|
21
|
+
it 'converts TIFF to JPEG' do
|
22
|
+
src_file = File.join(file_dir, 'data', 'test.tif')
|
23
|
+
ref_file = File.join(file_dir, 'data', 'test.jpg')
|
24
|
+
tgt_file = File.join('', 'tmp', 'test.jpg')
|
25
|
+
FileUtils.mkdir_p File.dirname(tgt_file)
|
26
|
+
converter.delete_date
|
27
|
+
result = converter.convert(src_file, tgt_file, :JPG)
|
28
|
+
expect(result).to eq tgt_file
|
29
|
+
compare = MiniMagick::Tool::Compare.new
|
30
|
+
compare << ref_file << tgt_file
|
31
|
+
compare.metric << 'MAE'
|
32
|
+
compare.fuzz << '1%'
|
33
|
+
compare << diff_file
|
34
|
+
compare.call {|_, _, status| expect(status).to be 0}
|
35
|
+
FileUtils.rm tgt_file, force: true
|
36
|
+
FileUtils.rm diff_file, force: true
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'converts TIFF to PNG' do
|
40
|
+
src_file = File.join(file_dir, 'data', 'test.tif')
|
41
|
+
ref_file = File.join(file_dir, 'data', 'test.png')
|
42
|
+
tgt_file = File.join('', 'tmp', 'test.png')
|
43
|
+
FileUtils.mkdir_p File.dirname(tgt_file)
|
44
|
+
converter.delete_date
|
45
|
+
converter.page(0)
|
46
|
+
result = converter.convert(src_file, tgt_file, :PNG)
|
47
|
+
expect(result).to eq tgt_file
|
48
|
+
compare = MiniMagick::Tool::Compare.new
|
49
|
+
compare << ref_file << tgt_file
|
50
|
+
compare.metric << 'MAE'
|
51
|
+
compare << diff_file
|
52
|
+
compare.call {|_, _, status| expect(status).to be 0}
|
53
|
+
FileUtils.rm tgt_file, force: true
|
54
|
+
FileUtils.rm diff_file, force: true
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'converts PDF to TIFF' do
|
58
|
+
src_file = File.join(file_dir, 'data', 'test.pdf')
|
59
|
+
ref_file = File.join(file_dir, 'data', 'test.pdf.tif')
|
60
|
+
tgt_file = File.join('', 'tmp', 'test.pdf.tif')
|
61
|
+
FileUtils.mkdir_p File.dirname(tgt_file)
|
62
|
+
converter.delete_date
|
63
|
+
result = converter.convert(src_file, tgt_file, :TIFF)
|
64
|
+
expect(result).to eq tgt_file
|
65
|
+
compare = MiniMagick::Tool::Compare.new
|
66
|
+
compare << ref_file << tgt_file
|
67
|
+
compare.metric << 'AE'
|
68
|
+
compare.fuzz << '100%'
|
69
|
+
compare << diff_file
|
70
|
+
compare.call {|_, _, status| expect(status).to be 0}
|
71
|
+
FileUtils.rm tgt_file, force: true
|
72
|
+
FileUtils.rm diff_file, force: true
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'converts TIFF to PNG with many options' do
|
76
|
+
src_file = File.join(file_dir, 'data', 'test.tif')
|
77
|
+
ref_file = File.join(file_dir, 'data', 'test-options.png')
|
78
|
+
tgt_file = File.join('', 'tmp', 'test-options.png')
|
79
|
+
FileUtils.mkdir_p File.dirname(tgt_file)
|
80
|
+
converter.watermark(text: 'RSPEC', size: 5, opacity: 0.1, rotation: 15, gap: 0.5, composition: 'modulate')
|
81
|
+
converter.delete_date
|
82
|
+
result = converter.convert(src_file, tgt_file, :PNG, options: {scale: '150%'})
|
83
|
+
expect(result).to eq tgt_file
|
84
|
+
compare = MiniMagick::Tool::Compare.new
|
85
|
+
compare << ref_file << tgt_file
|
86
|
+
compare.metric << 'AE'
|
87
|
+
compare.fuzz << '100%'
|
88
|
+
compare << diff_file
|
89
|
+
compare.call do |_stdin, _stdout, status|
|
90
|
+
expect(status).to be 0
|
91
|
+
end
|
92
|
+
FileUtils.rm tgt_file, force: true
|
93
|
+
FileUtils.rm diff_file, force: true
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'converts only first page of multipage TIFF to JP2' do
|
97
|
+
src_file = File.join(file_dir, 'data', 'multipage.tif')
|
98
|
+
ref_file = File.join(file_dir, 'data', 'multipage.tif.jp2')
|
99
|
+
tgt_file = File.join('', 'tmp', 'test.jp2')
|
100
|
+
FileUtils.mkdir_p File.dirname(tgt_file)
|
101
|
+
converter.delete_date
|
102
|
+
converter.quiet(true)
|
103
|
+
converter.page(0)
|
104
|
+
result = converter.convert(src_file, tgt_file, :JP2)
|
105
|
+
expect(result).to eq tgt_file
|
106
|
+
expect(File.exist?(tgt_file)).to be_truthy
|
107
|
+
compare = MiniMagick::Tool::Compare.new
|
108
|
+
compare << ref_file << tgt_file
|
109
|
+
compare.metric << 'MAE'
|
110
|
+
compare.fuzz << '10%'
|
111
|
+
compare << diff_file
|
112
|
+
compare.call {|_, _, status| expect(status).to be 0}
|
113
|
+
FileUtils.rm tgt_file, force: true
|
114
|
+
FileUtils.rm diff_file, force: true
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'converts TIFF to JP2' do
|
118
|
+
src_file = File.join(file_dir, 'data', 'test.tif')
|
119
|
+
tgt_file = File.join('', 'tmp', 'test.jp2')
|
120
|
+
FileUtils.mkdir_p File.dirname(tgt_file)
|
121
|
+
converter.delete_date
|
122
|
+
result = converter.convert(src_file, tgt_file, :JP2)
|
123
|
+
expect(result).to eq tgt_file
|
124
|
+
expect(File.exist?(tgt_file)).to be_truthy
|
125
|
+
FileUtils.rm tgt_file, force: true
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'JP2 Converter', if: File.exists?(Libis::Format::Config[:j2kdriver]) do
|
132
|
+
|
133
|
+
let(:converter) {Libis::Format::Converter::Jp2Converter.new}
|
134
|
+
let(:diff_file) {File.join('', 'tmp', 'diff.jpg')}
|
135
|
+
|
136
|
+
it 'converts TIFF to JP2' do
|
137
|
+
src_file = File.join(file_dir, 'data', 'test.tif')
|
138
|
+
tgt_file = File.join('', 'tmp', 'test.jp2')
|
139
|
+
FileUtils.mkdir_p File.dirname(tgt_file)
|
140
|
+
result = converter.convert(src_file, tgt_file, :JP2)
|
141
|
+
expect(result).to eq tgt_file
|
142
|
+
expect(File.exist?(tgt_file)).to be_truthy
|
143
|
+
FileUtils.rm tgt_file, force: true
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'converts only first page of multipage TIFF to JP2' do
|
147
|
+
src_file = File.join(file_dir, 'data', 'multipage.tif')
|
148
|
+
ref_file = File.join(file_dir, 'data', 'multipage.tif.jp2')
|
149
|
+
tgt_file = File.join('', 'tmp', 'test.jp2')
|
150
|
+
FileUtils.mkdir_p File.dirname(tgt_file)
|
151
|
+
result = converter.convert(src_file, tgt_file, :JP2)
|
152
|
+
expect(result).to eq tgt_file
|
153
|
+
expect(File.exist?(tgt_file)).to be_truthy
|
154
|
+
compare = MiniMagick::Tool::Compare.new
|
155
|
+
compare << ref_file << tgt_file
|
156
|
+
compare.metric << 'MAE'
|
157
|
+
compare.fuzz << '10%'
|
158
|
+
compare << diff_file
|
159
|
+
compare.call {|_, _, status| expect(status).to be 0}
|
160
|
+
FileUtils.rm tgt_file, force: true
|
161
|
+
FileUtils.rm diff_file, force: true
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|