dragonfly_libvips 0.1.2 → 0.1.3

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: f0aa118b1df8a61604fe2240b1cc118c4d50d7c8
4
- data.tar.gz: 9461fa176a4e3784426cd2a7df903eafcff4b868
3
+ metadata.gz: 8676f2cb2dbae9583ffe2af14c66af041f6e8f64
4
+ data.tar.gz: 54e568e8da1281466154cd4231aba259bd6740f1
5
5
  SHA512:
6
- metadata.gz: e4e70d8c380126264bb0019ab0417b7ed988a94a94b763766f74f162c7267fb7a65d9a20e1e439032263db19a665e8c64858b475222b61ad0fd99156bbe4faa2
7
- data.tar.gz: 85bdba42807a5200dc6448ccf64136624f56b9ef47c7e22e7d0c4412e7e054fb512afb1377f2c3b3984bcf3b7ff41f91f0eac3e0efef7d64320b3aae054ab856
6
+ metadata.gz: 313db91c7c616aacca3cc5b8bb6d1b689d3fcd513ab9b3a47b90fe1676f7688f08d77bd7803f192a03512068411ea84a18ec48bae65f114d7f12d71d6e926a14
7
+ data.tar.gz: 9b07b4d96eaa40c32c06d86f089b4b90cfe9756ffb9b3ba17df7866758d23f6430dd11263662beadbf050062029cc68ba6b77626a3c2007481440d730ff764a7
data/README.md CHANGED
@@ -109,9 +109,16 @@ image.vipsthumbnail('--size=100x100', { 'input_args' => 'page=2', 'output_args'
109
109
  corresponds to the command-line
110
110
 
111
111
  ```
112
- vipsthumbnail <original_path>[page=2] --size=100x100 -o <new-path>[Q=50]
112
+ vipsthumbnail <original_path>[page=2] --size=100x100 -o <new-path>[Q=50] --eprofile=./vendor/sRGB_v4_ICC_preference.icc
113
113
  ```
114
114
 
115
+ Please note that unless specified a default sRGB profile is added (required for conversion from CMYK, for example). It can be overridden by specifying alternative on in the processors args:
116
+
117
+ ```ruby
118
+ image.vipsthumbnail('--size=100x100 --eprofile=./my_custom_profile.icc')
119
+ ```
120
+
121
+
115
122
  ### Analysers
116
123
 
117
124
  The following methods are provided
@@ -1,3 +1,8 @@
1
1
  require 'dragonfly'
2
+ require 'dragonfly_libvips/dimensions'
2
3
  require 'dragonfly_libvips/plugin'
3
4
  require 'dragonfly_libvips/version'
5
+
6
+ module DragonflyLibvips
7
+ EPROFILE_PATH = File.expand_path('../vendor/sRGB_v4_ICC_preference.icc', __dir__)
8
+ end
@@ -0,0 +1,65 @@
1
+ module DragonflyLibvips
2
+ class Dimensions < Struct.new(:geometry, :orig_w, :orig_h)
3
+ def self.call(*args)
4
+ new(*args).call
5
+ end
6
+
7
+ def call
8
+ return OpenStruct.new(width: orig_w, height: orig_h) if do_not_resize_if_image_smaller_than_requested? || do_not_resize_if_image_larger_than_requested?
9
+ OpenStruct.new(width: width, height: height)
10
+ end
11
+
12
+ private
13
+
14
+ def width
15
+ if landscape?
16
+ dimensions_specified_by_width? ? dimensions.width : dimensions.height / aspect_ratio
17
+ else
18
+ dimensions_specified_by_height? ? dimensions.height / aspect_ratio : dimensions.width
19
+ end
20
+ end
21
+
22
+ def height
23
+ if landscape?
24
+ dimensions_specified_by_width? ? dimensions.width * aspect_ratio : dimensions.height
25
+ else
26
+ dimensions_specified_by_height? ? dimensions.height : dimensions.width * aspect_ratio
27
+ end
28
+ end
29
+
30
+ def dimensions
31
+ w, h = geometry.scan(/\A(\d*)x(\d*)/).flatten.map(&:to_f)
32
+ OpenStruct.new(width: w, height: h)
33
+ end
34
+
35
+ def aspect_ratio
36
+ orig_h.to_f / orig_w
37
+ end
38
+
39
+ def dimensions_specified_by_width?
40
+ dimensions.width > 0
41
+ end
42
+
43
+ def dimensions_specified_by_height?
44
+ dimensions.height > 0
45
+ end
46
+
47
+ def landscape?
48
+ aspect_ratio <= 1.0
49
+ end
50
+
51
+ def portrait?
52
+ !landscape?
53
+ end
54
+
55
+ def do_not_resize_if_image_smaller_than_requested?
56
+ return false unless geometry.include? '>'
57
+ orig_w < width && orig_h < height
58
+ end
59
+
60
+ def do_not_resize_if_image_larger_than_requested?
61
+ return false unless geometry.include? '<'
62
+ orig_w > width && orig_h > height
63
+ end
64
+ end
65
+ end
@@ -15,6 +15,8 @@ module DragonflyLibvips
15
15
  url_attributes.ext = format if format
16
16
  end
17
17
 
18
+ private
19
+
18
20
  def args_for_geometry(geometry, image_properties)
19
21
  case geometry
20
22
  when RESIZE_GEOMETRY then resize_args(geometry, image_properties)
@@ -22,32 +24,9 @@ module DragonflyLibvips
22
24
  end
23
25
  end
24
26
 
25
- private
26
-
27
27
  def resize_args(geometry, image_properties)
28
- w = image_properties['width']
29
- h = image_properties['height']
30
- ratio = w.to_f / h.to_f
31
- is_landscape = ratio > 1.0
32
-
33
- width, height = geometry.scan(/\A(\d*)x(\d*)/).flatten.map(&:to_i)
34
-
35
- case geometry
36
- when /\Ax\d+[#{OPERATORS}]?/
37
- width = is_landscape ? (ratio * height).round : height
38
- when /\A\d+x[#{OPERATORS}]?\z/
39
- height = is_landscape ? width : (width / ratio).round
40
- end
41
-
42
- case geometry
43
- when />\z/
44
- width, height = w, h if width >= w || height >= h
45
- when /<\z/
46
- width, height = w, h if width <= w && height <= h
47
- end
48
-
49
- dimensions = "#{width}x#{height}"
50
- "-s #{dimensions}"
28
+ res = Dimensions.call(geometry, image_properties['width'], image_properties['height'])
29
+ "-s #{res.width.round}x#{res.height.round}"
51
30
  end
52
31
  end
53
32
  end
@@ -13,6 +13,8 @@ module DragonflyLibvips
13
13
  output_args = "[#{output_args}]"
14
14
  end
15
15
 
16
+ args = [args, "--eprofile=#{EPROFILE_PATH}"].compact.join(' ') unless args.include?('eprofile')
17
+
16
18
  content.shell_update ext: format do |old_path, new_path|
17
19
  "#{vipsthumbnail_command} #{old_path}#{input_args} -o #{new_path}#{output_args} #{args}"
18
20
  end
@@ -1,3 +1,3 @@
1
1
  module DragonflyLibvips
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragonfly_libvips
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-20 00:00:00.000000000 Z
11
+ date: 2016-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dragonfly
@@ -114,6 +114,7 @@ files:
114
114
  - dragonfly_libvips.gemspec
115
115
  - lib/dragonfly_libvips.rb
116
116
  - lib/dragonfly_libvips/analysers/image_properties.rb
117
+ - lib/dragonfly_libvips/dimensions.rb
117
118
  - lib/dragonfly_libvips/plugin.rb
118
119
  - lib/dragonfly_libvips/processors/encode.rb
119
120
  - lib/dragonfly_libvips/processors/thumb.rb
@@ -124,6 +125,7 @@ files:
124
125
  - samples/landscape_beach.png
125
126
  - samples/memo.pdf
126
127
  - samples/white pixel.png
128
+ - vendor/sRGB_v4_ICC_preference.icc
127
129
  homepage: https://github.com/tomasc/dragonfly_libvips
128
130
  licenses:
129
131
  - MIT