morandi 0.9.0 → 0.9.1

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
  SHA1:
3
- metadata.gz: 699363674b014c312fbf514929f5d9a68bc7710c
4
- data.tar.gz: a3a8dc47dfb8e4b2a3c09904d44bd0ab32240043
3
+ metadata.gz: 60d7fd200d3a6c22ff2bc5b3defd81619c9f553d
4
+ data.tar.gz: 63ddd6689c0a505ced3f8059b3e4a0c0bdd2fc51
5
5
  SHA512:
6
- metadata.gz: 522a4bda18dfe5f5c5326f56385c2bf45bc0e14f5b2dd2946234be72e1d322d5b835e8cd3487e69d824d674bdd31daf508d67389f35fbdb0d8842e25ece61b39
7
- data.tar.gz: 06b08143b66b203c290e2b2493db345ac3d34ef82d95d663d5496fae9bcd965cef9b54dffb50ad9647ed349cc09f52dc5f474734ead26cad6da6f5feb56b3361
6
+ metadata.gz: 4500480f00a35c6ad07a167960236d23958967ab304662b1436cfa1d3fdf4922506fdb1270cdf297f15f0e4511c82609116cd90ce8e284dbb661ba526bfe8138
7
+ data.tar.gz: a2b83980c5b944d9d2783aecc87a820a0ba9dcb1aa3fc284430dd87cc8045a4cd735f25c065fdb7952d6a1725ab78cf165a5a3ca004b11bf6f87a36275631ba9
data/lib/morandi.rb CHANGED
@@ -24,20 +24,27 @@ module Morandi
24
24
  rescue
25
25
  false
26
26
  end
27
+ def self.default_icc_path(path)
28
+ "#{path}.icc.jpg"
29
+ end
27
30
 
28
- def initialize(file, scale_to, options)
31
+ def initialize(file, user_options, local_options={})
29
32
  @file = file
30
- #@size = size
31
- @scale_to = scale_to
32
- @options = options || {}
33
33
 
34
- @width, @height = options['output.width'], options['output.height']
34
+ user_options.keys.grep(/^path/).each { |k| user_options.delete(k) }
35
+
36
+ # Give priority to user_options
37
+ @options = (local_options || {}).merge(user_options || {})
38
+ @local_options = local_options
39
+
40
+ @scale_to = @options['output.max']
41
+ @width, @height = @options['output.width'], @options['output.height']
35
42
 
36
43
  load_file = @file
37
44
  type, width, height = Gdk::Pixbuf.get_file_info(load_file)
38
45
 
39
46
  if type.name.eql?('jpeg')
40
- icc_file = "#{@file}.icc.jpg"
47
+ icc_file = local_options['path.icc'] || ImageProcessor.default_icc_path(@file)
41
48
  if valid_jpeg?(icc_file) || system("jpgicc", "-q97", @file, icc_file)
42
49
  load_file = icc_file
43
50
  end
@@ -101,7 +108,7 @@ module Morandi
101
108
  #STDERR.puts "FILTER: #{options.inspect}"
102
109
  if options['brighten'].to_i.nonzero?
103
110
  brighten = [ [ 5 * options['brighten'], -100 ].max, 100 ].min
104
- STDERR.puts([:brighten, brighten].inspect)
111
+ #STDERR.puts([:brighten, brighten].inspect)
105
112
  @pb = PixbufUtils.brightness(@pb, brighten)
106
113
  end
107
114
  if options['gamma'] && (options['gamma'] != 1.0)
@@ -171,6 +178,10 @@ module Morandi
171
178
  return
172
179
  end
173
180
 
181
+ if crop.is_a?(String) && crop =~ /^\d+,\d+,\d+,\d+/
182
+ crop = crop.split(/,/).map(&:to_i)
183
+ end
184
+
174
185
  crop = nil unless crop.is_a?(Array) && crop.size.eql?(4) && crop.all? { |i|
175
186
  i.kind_of?(Numeric)
176
187
  }
@@ -243,8 +254,8 @@ module Morandi
243
254
  end
244
255
 
245
256
  module_function
246
- def process(file_in, settings, out_file)
247
- pro = ImageProcessor.new(file_in, settings['output.max'], settings)
257
+ def process(file_in, options, out_file, local_options = {})
258
+ pro = ImageProcessor.new(file_in, options, local_options)
248
259
  pro.process!
249
260
  pro.write_to_jpeg(out_file)
250
261
  end
@@ -1,3 +1,6 @@
1
+ require 'pango'
2
+ require 'colorscore'
3
+
1
4
  module Morandi
2
5
  class ImageOp
3
6
  class << self
@@ -1,3 +1,3 @@
1
1
  module Morandi
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
data/morandi.gemspec CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "cairo"
23
23
  spec.add_dependency "pixbufutils"
24
24
  spec.add_dependency "redeye"
25
+ spec.add_dependency "pango"
26
+ spec.add_dependency "colorscore"
25
27
 
26
28
  spec.add_development_dependency "bundler", "~> 1.5"
27
29
  spec.add_development_dependency "rake"
data/spec/morandi_spec.rb CHANGED
@@ -28,6 +28,39 @@ RSpec.describe Morandi, "#process_to_file" do
28
28
  expect(h).to eq(300)
29
29
  end
30
30
 
31
+ it "should use user supplied path.icc" do
32
+ src = 'sample/sample.jpg'
33
+ icc = '/tmp/this-is-secure-thing.jpg'
34
+ default_icc = Morandi::ImageProcessor.default_icc_path(src)
35
+ out = 'sample/out_icc.jpg'
36
+ File.unlink(default_icc) rescue nil
37
+ Morandi.process(src, { }, out, { 'path.icc' => icc })
38
+ expect(File).to exist(icc)
39
+ expect(File).not_to exist(default_icc)
40
+ end
41
+
42
+ it "should ignore user supplied path.icc" do
43
+ src = 'sample/sample.jpg'
44
+ icc = '/tmp/this-is-insecure-thing.jpg'
45
+ default_icc = Morandi::ImageProcessor.default_icc_path(src)
46
+ File.unlink(icc) rescue 0
47
+ File.unlink(default_icc) rescue 0
48
+ out = 'sample/out_icc.jpg'
49
+ Morandi.process(src, { 'path.icc' => icc, 'output.max' => 200 }, out)
50
+ expect(File).not_to exist(icc)
51
+ expect(File).to exist(default_icc)
52
+ end
53
+
54
+ it "should do cropping of images with a string" do
55
+ Morandi.process("sample/sample.jpg", {
56
+ 'crop' => "10,10,300,300"
57
+ }, out="sample/out_crop.jpg")
58
+ expect(File.exist?(out))
59
+ _,w,h = Gdk::Pixbuf.get_file_info(out)
60
+ expect(w).to eq(300)
61
+ expect(h).to eq(300)
62
+ end
63
+
31
64
  it "should reduce the size of images" do
32
65
  Morandi.process("sample/sample.jpg", {
33
66
  'output.max' => 200
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morandi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - |+
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-07-17 00:00:00.000000000 Z
14
+ date: 2015-07-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: gdk_pixbuf2
@@ -69,6 +69,34 @@ dependencies:
69
69
  - - '>='
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
+ - !ruby/object:Gem::Dependency
73
+ name: pango
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ - !ruby/object:Gem::Dependency
87
+ name: colorscore
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
72
100
  - !ruby/object:Gem::Dependency
73
101
  name: bundler
74
102
  requirement: !ruby/object:Gem::Requirement