mountable_image_server 0.2.0 → 0.3.0

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
- SHA1:
3
- metadata.gz: 1895ff21aa0c200b38703ddc0d92159d9f4c636c
4
- data.tar.gz: 9ecdb654c5066a1bba15684a669976a1c14f6149
2
+ SHA256:
3
+ metadata.gz: 63c63a9eab25e840d81dffc313e19a280367674550cb7e985b6d5a5c1947e060
4
+ data.tar.gz: ff7b2820a0a88aebd46245e0089271c527ae7823ca274ad74625ae5db88ad3fd
5
5
  SHA512:
6
- metadata.gz: 9ad5c4c99728c29a78c304c701c9896c51c738f642b488db48de7ddcb0914474dac7ed74d80c1473ebc19d67f09877a3002740bcaed77ff9e1201fc10110352a
7
- data.tar.gz: 7972011c57cca2bb7ed892903b05eb1f46f69e9ce49f7c0fa7b3664517c66aab554ddd9ca70ea27135a7e782d93a8c4cd750d1d93d63caa0cf7a857ce84d3e04
6
+ metadata.gz: 8c7d3c782dd5f6d86781be932683afa8be1a58ff83f9ff9c9d54865c74853f143f905c4390d6ae20e797401b1aecf9d42cbadaf85689dc08942abcd4c3e620dc
7
+ data.tar.gz: 4acd2cd370f9e7f085fd19d9caa87dfcea39b5443ba89d05f641ccbb77b923c28366dc728bbe6d1359ad8b20b9e29de029df3bb2179360523061fb09d46463a5
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .local-data/
data/README.md CHANGED
@@ -1 +1,5 @@
1
- To be written.
1
+ # Publish on RubyGems.org
2
+
3
+ 1. Increment `lib/mountable_image_server/version.rb` to your liking.
4
+ 2. Make a Git commit.
5
+ 3. Run `bundle exec rake release`.
@@ -6,14 +6,22 @@ module MountableImageServer
6
6
  class ImageProcessor
7
7
  include Skeptick
8
8
 
9
- VALID_PARAMETERS = [:fit, :crop, :w, :h, :q, :darken]
9
+ # Accepted parameters and values:
10
+ # `fit` - Approach how to interpret width and height, use 'crop' (cropping) or 'clip' (resizing)
11
+ # `w` - Width of image in pixels
12
+ # `h` - Height of image in pixels
13
+ # `q` - Quality of image, use value between 0 (worst) and 100 (best)
14
+ # `darken` - Blends image with black color, use value between 0 (no black) and 100 (completely black)
15
+ # `fm` - Format of image, use 'jpg', 'png', 'gif', ...
16
+ VALID_PARAMETERS = [:fit, :w, :h, :q, :darken, :fm]
10
17
 
11
18
  def initialize(path, parameters)
12
19
  @path = path
20
+ @file_format = path.extname.downcase.scan(/[^\.]+/).last
13
21
  @parameters = parameters.select do |key, value|
14
- VALID_PARAMETERS.include?(key.to_sym)
22
+ VALID_PARAMETERS.include?(key.to_sym) && value =~ /\S+/
15
23
  end.map do |key, value|
16
- [key.to_sym, value]
24
+ [key.to_sym, value.strip.downcase]
17
25
  end.to_h
18
26
  end
19
27
 
@@ -22,15 +30,32 @@ module MountableImageServer
22
30
 
23
31
  parameters[:fit] ||= 'clip'
24
32
 
33
+ if parameters[:fm] && parameters[:fm] == file_format
34
+ parameters.delete(:fm)
35
+ end
36
+
37
+ if parameters[:fm]
38
+ extension = ".#{parameters[:fm]}"
39
+ else
40
+ extension = ".#{file_format}"
41
+ end
42
+
43
+ if parameters[:fm] && parameters[:fm] != file_format && file_format == 'gif'
44
+ input_path = "#{path}[0]"
45
+ else
46
+ input_path = path
47
+ end
48
+
25
49
  operations_queue = [
50
+ format_operations,
26
51
  resize_operations,
27
52
  crop_operations,
28
53
  quality_operations,
29
- darken_operations
54
+ darken_operations,
30
55
  ].reduce([], :+)
31
56
 
32
- Tempfile.create(['processed-image', path.extname]) do |file|
33
- command = convert(path, to: file.path) do
57
+ Tempfile.create(['processed-image', extension]) do |file|
58
+ command = convert(input_path, to: file.path) do
34
59
  operations_queue.each do |operation|
35
60
  set *operation
36
61
  end
@@ -43,7 +68,7 @@ module MountableImageServer
43
68
  end
44
69
 
45
70
  private
46
- attr_reader :parameters, :path
71
+ attr_reader :parameters, :path, :file_format
47
72
 
48
73
  def darken_operations
49
74
  return [] unless parameters[:darken]
@@ -79,5 +104,13 @@ module MountableImageServer
79
104
  [:quality, parameters[:q]]
80
105
  ]
81
106
  end
107
+
108
+ def format_operations
109
+ return [] unless parameters[:fm]
110
+
111
+ [
112
+ [:format, parameters[:fm]]
113
+ ]
114
+ end
82
115
  end
83
116
  end
@@ -1,3 +1,3 @@
1
1
  module MountableImageServer
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -19,12 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "bundler", "~> 2.1"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "minitest", "~> 5.0"
25
25
  spec.add_development_dependency "rack-test", "~> 0.6.3"
26
26
 
27
27
  spec.add_runtime_dependency "sinatra", "~> 2.0.0.rc1"
28
- spec.add_runtime_dependency "dry-configurable", "~> 0.1.6"
28
+ spec.add_runtime_dependency "dry-configurable", ">= 0.1.6"
29
29
  spec.add_runtime_dependency "skeptick", "~> 0.2.1"
30
30
  end
@@ -0,0 +1,27 @@
1
+ {
2
+ pkgs ? import (fetchGit {
3
+ url = https://github.com/NixOS/nixpkgs-channels;
4
+ ref = "nixos-20.03";
5
+ }) {},
6
+ ruby ? pkgs.ruby_2_5,
7
+ bundler ? pkgs.bundler.override { inherit ruby; }
8
+ }:
9
+
10
+ pkgs.mkShell {
11
+ buildInputs = with pkgs; [
12
+ ruby
13
+ bundler
14
+ git
15
+ sqlite
16
+ zlib
17
+ phantomjs
18
+ rubyPackages_2_5.nokogiri
19
+ libiconv
20
+ ];
21
+
22
+ shellHook = ''
23
+ mkdir -p .local-data/gems
24
+ export GEM_HOME=$PWD/.local-data/gems
25
+ export GEM_PATH=$GEM_HOME
26
+ '';
27
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mountable_image_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Strauß
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-10 00:00:00.000000000 Z
11
+ date: 1970-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.12'
19
+ version: '2.1'
20
20
  type: :development
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: '1.12'
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -84,14 +84,14 @@ dependencies:
84
84
  name: dry-configurable
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: 0.1.6
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.1.6
97
97
  - !ruby/object:Gem::Dependency
@@ -131,6 +131,7 @@ files:
131
131
  - lib/mountable_image_server/server.rb
132
132
  - lib/mountable_image_server/version.rb
133
133
  - mountable_image_server.gemspec
134
+ - shell.nix
134
135
  homepage: https://github.com/stravid/mountable_image_server
135
136
  licenses:
136
137
  - MIT
@@ -150,8 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
151
  - !ruby/object:Gem::Version
151
152
  version: '0'
152
153
  requirements: []
153
- rubyforge_project:
154
- rubygems_version: 2.5.1
154
+ rubygems_version: 3.1.2
155
155
  signing_key:
156
156
  specification_version: 4
157
157
  summary: Simple mountable server for processing images on the fly.