leifcr-refile-mini_magick 0.2.1 → 0.2.2

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: 73967411699252c6e946a016ed98ba58125243c7
4
- data.tar.gz: ab8981685fa3822069962f2b343c7905fa1a6bc9
3
+ metadata.gz: d7a205a530752fc9b909fa15a168a3aea6046b6c
4
+ data.tar.gz: d8d66c11ca574ed633f77d73d2a19bba3bd2e4b2
5
5
  SHA512:
6
- metadata.gz: 269097afcf4239922b2460c29904c4bec486ab97738c33d3295b83249040dc85d77d231f6f7c2a4b04b758e2ca74e8de2088efb482f7179ff94935e993fb3c80
7
- data.tar.gz: 7ccbca17ac880a52f155993b28ad576d22fc1fbeffd7f45c6c1a0431bd6bc2d23eab62128bd7eefed591292eaa9f55a4ab8c7db38f6adaa8bc2a4124fd3fed84
6
+ metadata.gz: 757c16cc18b7e9e0b9c512724eaf8b6cb9bd3349ff3b1ce7a45d556cc62b173391657692f63aef39c70a6e0d3a6164aa5e2e533341e6a2ca05e59d1dafd2b202
7
+ data.tar.gz: 03b68ee2bb606d5d34080b0c8bdbadca1ed8d09f7df3adcd1f418c1a3a800b3e0713946ffed8de22e1c2ebcf7decba19c1dc9847f5aa6ffaab7de49955bafdd3
@@ -13,12 +13,11 @@ module Refile
13
13
  # Changes the image encoding format to the given format
14
14
  #
15
15
  # @see http://www.imagemagick.org/script/command-line-options.php#format
16
- # @param [File] img the image to convert
17
- # @param [String] format the format to convert to
18
- # @yield [MiniMagick::Tool::Mogrify, MiniMagick::Tool::Convert]
19
- # @return [File, Tempfile]
20
- def convert(img, format, &block)
21
- processor.convert!(img, format, &block)
16
+ # @param [ImageProcesing::Pipeline] pipeline processing pipeline to call
17
+ # @param [String] format the format to convert to
18
+ # @return [Tempfile]
19
+ def convert(pipeline, format)
20
+ pipeline.convert!(format)
22
21
  end
23
22
 
24
23
  # Resize the image to fit within the specified dimensions while retaining
@@ -27,13 +26,13 @@ module Refile
27
26
  # narrower than specified in either dimension but will not be larger than
28
27
  # the specified values.
29
28
  #
30
- # @param [File] img the image to convert
31
- # @param [#to_s] width the maximum width
32
- # @param [#to_s] height the maximum height
33
- # @yield [MiniMagick::Tool::Mogrify, MiniMagick::Tool::Convert]
34
- # @return [File, Tempfile]
35
- def limit(img, width, height, &block)
36
- processor.resize_to_limit!(img, width, height, &block)
29
+ # @param [ImageProcesing::Pipeline] pipeline processing pipeline to call
30
+ # @param [#to_s] width the maximum width
31
+ # @param [#to_s] height the maximum height
32
+ # @yield [MiniMagick::Tool::Convert]
33
+ # @return [Tempfile]
34
+ def limit(pipeline, width, height)
35
+ pipeline.resize_to_limit!(width || "!", height || "!")
37
36
  end
38
37
 
39
38
  # Resize the image to fit within the specified dimensions while retaining
@@ -41,13 +40,12 @@ module Refile
41
40
  # specified in the smaller dimension but will not be larger than the
42
41
  # specified values.
43
42
  #
44
- # @param [File] img the image to convert
45
- # @param [#to_s] width the width to fit into
46
- # @param [#to_s] height the height to fit into
47
- # @yield [MiniMagick::Tool::Mogrify, MiniMagick::Tool::Convert]
48
- # @return [File, Tempfile]
49
- def fit(img, width, height, &block)
50
- processor.resize_to_fit!(img, width, height, &block)
43
+ # @param [ImageProcesing::Pipeline] pipeline processing pipeline to call
44
+ # @param [#to_s] width the width to fit into
45
+ # @param [#to_s] height the height to fit into
46
+ # @return [Tempfile]
47
+ def fit(pipeline, width, height)
48
+ pipeline.resize_to_fit!(width, height)
51
49
  end
52
50
 
53
51
  # Resize the image so that it is at least as large in both dimensions as
@@ -59,15 +57,14 @@ module Refile
59
57
  # By default, the center part of the image is kept, and the remainder
60
58
  # cropped off, but this can be changed via the `gravity` option.
61
59
  #
62
- # @param [File] img the image to convert
63
- # @param [#to_s] width the width to fill out
64
- # @param [#to_s] height the height to fill out
65
- # @param [String] gravity which part of the image to focus on
66
- # @yield [MiniMagick::Tool::Mogrify, MiniMagick::Tool::Convert]
67
- # @return [File, Tempfile]
60
+ # @param [ImageProcesing::Pipeline] pipeline processing pipeline to call
61
+ # @param [#to_s] width the width to fill out
62
+ # @param [#to_s] height the height to fill out
63
+ # @param [String] gravity which part of the image to focus on
64
+ # @return [Tempfile]
68
65
  # @see http://www.imagemagick.org/script/command-line-options.php#gravity
69
- def fill(img, width, height, gravity = "Center", &block)
70
- processor.resize_to_fill!(img, width, height, gravity: gravity, &block)
66
+ def fill(pipeline, width, height, gravity = "Center")
67
+ pipeline.resize_to_fill!(width, height, gravity: gravity)
71
68
  end
72
69
 
73
70
  # Resize the image to fit within the specified dimensions while retaining
@@ -82,17 +79,16 @@ module Refile
82
79
  # By default, the image will be placed in the center but this can be
83
80
  # changed via the `gravity` option.
84
81
  #
85
- # @param [MiniMagick::image] img the image to convert
86
- # @param [#to_s] width the width to fill out
87
- # @param [#to_s] height the height to fill out
88
- # @param [string] background the color to use as a background
89
- # @param [string] gravity which part of the image to focus on
90
- # @yield [MiniMagick::Tool::Mogrify, MiniMagick::Tool::Convert]
91
- # @return [File, Tempfile]
82
+ # @param [ImageProcesing::Pipeline] pipeline processing pipeline to call
83
+ # @param [#to_s] width the width to fill out
84
+ # @param [#to_s] height the height to fill out
85
+ # @param [string] background the color to use as a background
86
+ # @param [string] gravity which part of the image to focus on
87
+ # @return [Tempfile]
92
88
  # @see http://www.imagemagick.org/script/color.php
93
89
  # @see http://www.imagemagick.org/script/command-line-options.php#gravity
94
- def pad(img, width, height, background = "transparent", gravity = "Center", &block)
95
- processor.resize_and_pad!(img, width, height, background: background, gravity: gravity, &block)
90
+ def pad(pipeline, width, height, background = "transparent", gravity = "Center")
91
+ pipeline.resize_and_pad!(width, height, gravity: gravity, background: background)
96
92
  end
97
93
 
98
94
  # Resample the image to fit within the specified resolution while retaining
@@ -101,14 +97,13 @@ module Refile
101
97
  # The resulting image will always be the same pixel size as the source with
102
98
  # an adjusted resolution dimensions.
103
99
  #
104
- # @param [minimagick::image] img the image to convert
105
- # @param [#to_s] width the dpi width
106
- # @param [#to_s] height the dpi height
107
- # @yield [MiniMagick::Tool::Mogrify, MiniMagick::Tool::Convert]
108
- # @return [File, Tempfile]
100
+ # @param [ImageProcesing::Pipeline] pipeline processing pipeline to call
101
+ # @param [#to_s] width the dpi width
102
+ # @param [#to_s] height the dpi height
103
+ # @return [Tempfile]
109
104
  # @see http://www.imagemagick.org/script/command-line-options.php#resample
110
- def resample(img, width, height, &block)
111
- processor.resample!(img, width, height, &block)
105
+ def resample(pipeline, width, height)
106
+ pipeline.resample!("#{width}x#{height}")
112
107
  end
113
108
 
114
109
  # Process the given file. The file will be processed via one of the
@@ -117,18 +112,16 @@ module Refile
117
112
  #
118
113
  # If the format is given it will convert the image to the given file format.
119
114
  #
120
- # @param [Tempfile] file the file to manipulate
121
- # @param [String] format the file format to convert to
122
- # @return [File] the processed file
115
+ # @param [File] file the file to manipulate
116
+ # @param [String] format the file format to convert to
117
+ # @yield [MiniMagick::Tool::Convert]
118
+ # @return [Tempfile] the processed file
123
119
  def call(file, *args, format: nil, &block)
124
- file = processor.convert!(file, format) if format
125
- send(@method, file, *args, &block)
126
- end
127
-
128
- private
120
+ pipeline = ImageProcessing::MiniMagick.source(file)
121
+ pipeline = pipeline.convert(format) if format
122
+ pipeline = pipeline.custom(&block)
129
123
 
130
- def processor
131
- ImageProcessing::MiniMagick
124
+ send(@method, pipeline, *args)
132
125
  end
133
126
  end
134
127
  end
@@ -1,5 +1,5 @@
1
1
  module Refile
2
2
  class MiniMagick
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "refile", "~> 0.5"
21
- spec.add_dependency "image_processing", ">= 0.4.1", "< 1.0"
22
- spec.add_dependency "mini_magick", ">= 4.3.5"
20
+ spec.add_dependency "refile", "~> 0.6"
21
+ spec.add_dependency "image_processing", "~> 1.1"
22
+ spec.add_dependency "mini_magick", "~> 4.0"
23
23
  end
@@ -38,6 +38,45 @@ RSpec.describe Refile::MiniMagick do
38
38
  expect { |b| Refile::MiniMagick.new(:limit).call(portrait, "400", "400", &b) }
39
39
  .to yield_with_args(MiniMagick::Tool)
40
40
  end
41
+
42
+ context "when width or height is nil" do
43
+ it "resizes the image up to only a width limit" do
44
+ file = Refile::MiniMagick.new(:limit).call(portrait, "400", nil)
45
+ result = ::MiniMagick::Image.new(file.path)
46
+ expect(result.width).to eq(400)
47
+ expect(result.height).to eq(800)
48
+ end
49
+
50
+ it "resizes the image up to only a height limit" do
51
+ file = Refile::MiniMagick.new(:limit).call(portrait, nil, "400")
52
+ result = ::MiniMagick::Image.new(file.path)
53
+ expect(result.width).to eq(600)
54
+ expect(result.height).to eq(400)
55
+ end
56
+ end
57
+
58
+ context "when use '!' to limit a exact width or height" do
59
+ it "resizes the image up to only a width limit" do
60
+ file = Refile::MiniMagick.new(:limit).call(portrait, "400", "800!")
61
+ result = ::MiniMagick::Image.new(file.path)
62
+ expect(result.width).to eq(400)
63
+ expect(result.height).to eq(800)
64
+ end
65
+
66
+ it "resizes the image up to only a height limit" do
67
+ file = Refile::MiniMagick.new(:limit).call(portrait, "600!", "400")
68
+ result = ::MiniMagick::Image.new(file.path)
69
+ expect(result.width).to eq(600)
70
+ expect(result.height).to eq(400)
71
+ end
72
+
73
+ it "resizes the image but it doesn't go beyong the image dimensions" do
74
+ file = Refile::MiniMagick.new(:limit).call(portrait, "300", "1000!")
75
+ result = ::MiniMagick::Image.new(file.path)
76
+ expect(result.width).to eq(300)
77
+ expect(result.height).to eq(800)
78
+ end
79
+ end
41
80
  end
42
81
 
43
82
  describe "#fit" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leifcr-refile-mini_magick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2018-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: refile
@@ -16,48 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
19
+ version: '0.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.5'
26
+ version: '0.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: image_processing
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.4.1
34
- - - "<"
31
+ - - "~>"
35
32
  - !ruby/object:Gem::Version
36
- version: '1.0'
33
+ version: '1.1'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 0.4.1
44
- - - "<"
38
+ - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '1.0'
40
+ version: '1.1'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: mini_magick
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
- - - ">="
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: 4.3.5
47
+ version: '4.0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
- - - ">="
52
+ - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: 4.3.5
54
+ version: '4.0'
61
55
  description:
62
56
  email:
63
57
  - jonas.nicklas@gmail.com
@@ -96,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
90
  version: '0'
97
91
  requirements: []
98
92
  rubyforge_project:
99
- rubygems_version: 2.6.8
93
+ rubygems_version: 2.6.14
100
94
  signing_key:
101
95
  specification_version: 4
102
96
  summary: Image processing via MiniMagick for Refile