libis-format 0.9.20 → 0.9.21

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
  SHA1:
3
- metadata.gz: 86362989ffe452b37e82bc647c5abebc480d2a5f
4
- data.tar.gz: d9d19fd300c54b12e26a2c0b1dcce7416452fe55
3
+ metadata.gz: ca0fa2347db2ac8e525a5f4d9a2e0dd5b6041c3e
4
+ data.tar.gz: 4e35f07c555c7535acfd7529fd5cbd5d66d93013
5
5
  SHA512:
6
- metadata.gz: 42eb64630ab74678939d4e9b7144296c20f803fe48aef907d1e28dac329f96607442a5b1286eded9729fe9005d7f6cac7b094767b0bc2f51c1c9a29c77470b44
7
- data.tar.gz: cbc01c829480e78cbb15b1d0905aa3b9823b148084ddbab4d0aae9d9a76fcb86bb8ab9dcfe35cea2e3f2a2d1f6280c0ca89f6818bd88a3e1e5a01d7550039c73
6
+ metadata.gz: 5d3885c3601936d75e4acd3c229ed4157dd44b759632f8b65ea46edc180189d57892f0f0f42050170e269ae0386e9e6cdb0870071a684355d27160b174166be0
7
+ data.tar.gz: d92986e11cb2d1e4b35f60781d81d4a6a1bc5c7aba1b950abfc9e01f3b862891e4d57c1a5e758681c40fbe98b548980a0825df42471b9061f801c4d4f61951bf
@@ -10,6 +10,7 @@ module Libis
10
10
  Config[:converter_chain_max_level] = 8
11
11
 
12
12
  Config[:java_path] = 'java'
13
+ Config[:j2kdriver] = 'j2kdriver'
13
14
  Config[:soffice_path] = 'soffice'
14
15
  Config[:ghostscript_path] = 'gs'
15
16
  # Config[:pdfa_path] =
@@ -59,8 +59,12 @@ module Libis
59
59
  @options[:colorspace] = value
60
60
  end
61
61
 
62
+ def delete_date
63
+ @delete_date = true
64
+ end
65
+
62
66
  def profile(icc)
63
- @options[:profile] = icc
67
+ @profile = icc
64
68
  end
65
69
 
66
70
  # Create or use a watermark image.
@@ -186,12 +190,6 @@ module Libis
186
190
  convert.resize("#{image.width / @wm_size}x#{image.height / @wm_size}").write('mpr:watermark').delete.+
187
191
  end
188
192
 
189
- conversions = {}
190
- icc_options = {}
191
- @options.each do |o, v|
192
- ([:colorspace, :profile].include?(o) ? icc_options : conversions)[o] = v
193
- end
194
-
195
193
  convert << source
196
194
  convert.flatten if format == :JPG
197
195
  if @wm_image
@@ -206,13 +204,16 @@ module Libis
206
204
  end
207
205
 
208
206
  @flags.each { |f, v| v.is_a?(FalseClass) ? convert.send(f).+ : convert.send(f) }
207
+ if @delete_date
208
+ convert << '+set' << 'modify-date' << '+set' << 'create-date'
209
+ end
209
210
 
210
- unless conversions.empty?
211
+ unless @options.empty?
211
212
  convert.colorspace('RGB')
212
- conversions.each { |o, v| convert.send(o, v) }
213
- convert.colorspace('sRGB') if icc_options.empty?
213
+ @options.each { |o, v| convert.send(o, v) }
214
+ convert.colorspace('sRGB') unless @options[:colorspace]
214
215
  end
215
- icc_options.each { |o, v| convert.send(o, v) }
216
+ convert.profile @profile if @profile
216
217
 
217
218
  convert.format(format)
218
219
  convert << target
@@ -0,0 +1,111 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+ require 'libis/format/identifier'
5
+
6
+ require 'mini_magick'
7
+ require 'fileutils'
8
+
9
+ MiniMagick.logger.level = ::Logger::ERROR
10
+
11
+ module Libis
12
+ module Format
13
+ module Converter
14
+
15
+ class Jp2Converter < Libis::Format::Converter::Base
16
+
17
+ def self.input_types(format = nil)
18
+ [:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF]
19
+ end
20
+
21
+ def self.output_types(_ = nil)
22
+ [:JP2]
23
+ end
24
+
25
+ def initialize
26
+ super
27
+ @options = {
28
+ color_xform: false,
29
+ error_resilience: :ALL,
30
+ lossless: true,
31
+ progression_order: 'RLCP',
32
+ tile_size: [1024, 1024],
33
+ codeblock_size: [6, 6],
34
+ }
35
+ end
36
+
37
+ def j2kdriver(_)
38
+ #force usage of this converter
39
+ end
40
+
41
+ def color_xform(flag = true)
42
+ @options[:color_xform] = flag
43
+ end
44
+
45
+ def error_resilience(value = :ALL)
46
+ @options[:error_resilience] = value
47
+ end
48
+
49
+ def lossless(value = true)
50
+ @options[:lossless] = value
51
+ end
52
+
53
+ def progression_order(value = 'RLCP')
54
+ @options[:progression_order] = value
55
+ end
56
+
57
+ def tile_size(width = 1024, height = 1024)
58
+ @options[:tile_size] = [width, height]
59
+ end
60
+
61
+ def codeblock_size(height = 6, width = 6)
62
+ @options[:codeblock_size] = [height, width]
63
+ end
64
+
65
+ def convert(source, target, format, opts = {})
66
+ super
67
+
68
+ FileUtils.mkpath(File.dirname(target))
69
+
70
+ options = []
71
+
72
+ @options.each do |key, value|
73
+ case key
74
+ when :color_xform
75
+ options << '--set-output-j2k-color-xform' << value ? 'YES' : 'NO'
76
+ when :error_resilience
77
+ options << '--set-output-j2k-error-resilience' << value.to_s
78
+ when :lossless
79
+ if value
80
+ options << '--set-output-j2k-xform' << 'R53' << '5' << '--set-output-j2k-ratio' << '0'
81
+ else
82
+ options << '--set-output-j2k-xform' << 'I97' << '--set-output-j2k-psnr' << '46'
83
+ end
84
+ when :progression_order
85
+ options << '--set-output-j2k-progression-order' << value.to_s
86
+ when :tile_size
87
+ options << '--set-output-j2k-tile-size' << value[0].to_s << value[1].to_s
88
+ when :codeblock_size
89
+ options << '--set-output-j2k-codeblock-size' << value[0].to_s << value[1].to_s
90
+ else
91
+ #do nothing
92
+ end
93
+ end
94
+
95
+
96
+ Libis::Tools::Command.run(
97
+ Libis::Format::Config[:j2kdriver],
98
+ '--input-file-name', source,
99
+ '--output-file-name', target,
100
+ '--set-output-type', 'JP2',
101
+ *options
102
+ )
103
+
104
+ target
105
+
106
+
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -1,5 +1,5 @@
1
1
  module Libis
2
2
  module Format
3
- VERSION = '0.9.20'
3
+ VERSION = '0.9.21'
4
4
  end
5
5
  end
@@ -83,9 +83,11 @@ describe 'Converters' do
83
83
  ref_file = File.join(file_dir, 'data', 'test.jpg')
84
84
  tgt_file = File.join('', 'tmp', 'test.jpg')
85
85
  FileUtils.mkdir_p File.dirname(tgt_file)
86
+ converter.delete_date
86
87
  result = converter.convert(src_file, tgt_file, :JPG)
87
88
  expect(result).to eq tgt_file
88
- expect(tgt_file).to be_same_file_as ref_file
89
+ compare = MiniMagick::Tool::Compare.new { |cmp| cmp << '-metric' << 'mae' << ref_file << tgt_file << 'null:' }
90
+ expect(compare).to_not be_nil
89
91
  FileUtils.rm tgt_file, force: true
90
92
  end
91
93
 
@@ -94,9 +96,11 @@ describe 'Converters' do
94
96
  ref_file = File.join(file_dir, 'data', 'test.png')
95
97
  tgt_file = File.join('', 'tmp', 'test.png')
96
98
  FileUtils.mkdir_p File.dirname(tgt_file)
99
+ converter.delete_date
97
100
  result = converter.convert(src_file, tgt_file, :PNG)
98
101
  expect(result).to eq tgt_file
99
- expect(tgt_file).to be_same_file_as ref_file
102
+ compare = MiniMagick::Tool::Compare.new { |cmp| cmp << '-metric' << 'mae' << ref_file << tgt_file << 'null:' }
103
+ expect(compare).to_not be_nil
100
104
  FileUtils.rm tgt_file, force: true
101
105
  end
102
106
 
@@ -105,6 +109,7 @@ describe 'Converters' do
105
109
  ref_file = File.join(file_dir, 'data', 'test.pdf.tif')
106
110
  tgt_file = File.join('', 'tmp', 'test.pdf.tif')
107
111
  FileUtils.mkdir_p File.dirname(tgt_file)
112
+ converter.delete_date
108
113
  result = converter.convert(src_file, tgt_file, :TIFF)
109
114
  expect(result).to eq tgt_file
110
115
  expect(tgt_file).to be_same_file_as ref_file
@@ -117,9 +122,11 @@ describe 'Converters' do
117
122
  tgt_file = File.join('', 'tmp', 'test-options.jpg')
118
123
  FileUtils.mkdir_p File.dirname(tgt_file)
119
124
  converter.watermark(text: 'RSPEC', size: 5, opacity: 0.1, rotation: 15, gap: 0.5, composition: 'modulate')
125
+ converter.delete_date
120
126
  result = converter.convert(src_file, tgt_file, :JPG, options: {scale: '150%', quality: '70%'})
121
127
  expect(result).to eq tgt_file
122
- expect(tgt_file).to be_same_file_as ref_file
128
+ compare = MiniMagick::Tool::Compare.new { |cmp| cmp << '-metric' << 'mae' << ref_file << tgt_file << 'null:' }
129
+ expect(compare).to_not be_nil
123
130
  FileUtils.rm tgt_file, force: true
124
131
  end
125
132
 
Binary file
data/spec/data/test.jpg CHANGED
Binary file
data/spec/data/test.png CHANGED
Binary file
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: 0.9.20
4
+ version: 0.9.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Dekeyser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-25 00:00:00.000000000 Z
11
+ date: 2016-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -157,6 +157,7 @@ files:
157
157
  - lib/libis/format/converter/base.rb
158
158
  - lib/libis/format/converter/chain.rb
159
159
  - lib/libis/format/converter/image_converter.rb
160
+ - lib/libis/format/converter/jp2_converter.rb
160
161
  - lib/libis/format/converter/office_converter.rb
161
162
  - lib/libis/format/converter/pdf_converter.rb
162
163
  - lib/libis/format/converter/repository.rb