mountable_image_server 0.1.0 → 0.2.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
2
  SHA1:
3
- metadata.gz: 0ad348f1212103893cc82cc3a60fa77e5ecdce3a
4
- data.tar.gz: 2258abacb79c145cf2bd648b812696491d6f36e6
3
+ metadata.gz: 1895ff21aa0c200b38703ddc0d92159d9f4c636c
4
+ data.tar.gz: 9ecdb654c5066a1bba15684a669976a1c14f6149
5
5
  SHA512:
6
- metadata.gz: 9f3fa96f6bd943a6a210b83c440c44e883c4481587a974798edea71e762194fa54da9a3b3c1a72939d66380f513b934d3b23756574d80c4d8e7f6bde72d27694
7
- data.tar.gz: 126a9b49b548ab4fa815de5381a7d4b947de637aac46998da5f5b39a73d412b9c51745bdc3531a0065593cdcded98ab7c2aa8c6314e7683f3809f3936a1672a6
6
+ metadata.gz: 9ad5c4c99728c29a78c304c701c9896c51c738f642b488db48de7ddcb0914474dac7ed74d80c1473ebc19d67f09877a3002740bcaed77ff9e1201fc10110352a
7
+ data.tar.gz: 7972011c57cca2bb7ed892903b05eb1f46f69e9ce49f7c0fa7b3664517c66aab554ddd9ca70ea27135a7e782d93a8c4cd750d1d93d63caa0cf7a857ce84d3e04
@@ -0,0 +1 @@
1
+ 2.3.1
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require './lib/mountable_image_server'
4
+
5
+ MountableImageServer.configure do |config|
6
+ config.sources << './test/fixtures'
7
+ end
8
+
9
+ run MountableImageServer::Server.new
@@ -6,18 +6,34 @@ module MountableImageServer
6
6
  class ImageProcessor
7
7
  include Skeptick
8
8
 
9
+ VALID_PARAMETERS = [:fit, :crop, :w, :h, :q, :darken]
10
+
9
11
  def initialize(path, parameters)
10
- @parameters = parameters
11
12
  @path = path
13
+ @parameters = parameters.select do |key, value|
14
+ VALID_PARAMETERS.include?(key.to_sym)
15
+ end.map do |key, value|
16
+ [key.to_sym, value]
17
+ end.to_h
12
18
  end
13
19
 
14
20
  def run(&block)
15
- yield(Pathname(path)) and return unless parameters[:h] || parameters[:w] || parameters[:q]
21
+ yield(Pathname(path)) and return unless parameters.any?
22
+
23
+ parameters[:fit] ||= 'clip'
24
+
25
+ operations_queue = [
26
+ resize_operations,
27
+ crop_operations,
28
+ quality_operations,
29
+ darken_operations
30
+ ].reduce([], :+)
16
31
 
17
32
  Tempfile.create(['processed-image', path.extname]) do |file|
18
33
  command = convert(path, to: file.path) do
19
- set :resize, "#{parameters[:w]}x#{parameters[:h]}>" if parameters[:h] || parameters[:w]
20
- set :quality, parameters[:q] if parameters[:q]
34
+ operations_queue.each do |operation|
35
+ set *operation
36
+ end
21
37
  end
22
38
 
23
39
  command.run
@@ -28,5 +44,40 @@ module MountableImageServer
28
44
 
29
45
  private
30
46
  attr_reader :parameters, :path
47
+
48
+ def darken_operations
49
+ return [] unless parameters[:darken]
50
+
51
+ [
52
+ [:fill, 'black'],
53
+ [:colorize, parameters[:darken]]
54
+ ]
55
+ end
56
+
57
+ def resize_operations
58
+ return [] unless (parameters[:fit] == 'clip') && (parameters[:h] || parameters[:w])
59
+
60
+ [
61
+ [:resize, "#{parameters[:w]}x#{parameters[:h]}>"]
62
+ ]
63
+ end
64
+
65
+ def crop_operations
66
+ return [] unless parameters[:fit] == 'crop' && parameters[:h] && parameters[:w]
67
+
68
+ [
69
+ [:resize, "#{parameters[:w]}x#{parameters[:h]}^"],
70
+ [:gravity, 'center'],
71
+ [:extent, "#{parameters[:w]}x#{parameters[:h]}"]
72
+ ]
73
+ end
74
+
75
+ def quality_operations
76
+ return [] unless parameters[:q]
77
+
78
+ [
79
+ [:quality, parameters[:q]]
80
+ ]
81
+ end
31
82
  end
32
83
  end
@@ -7,6 +7,19 @@ module MountableImageServer
7
7
  get '/:fid' do |fid|
8
8
  locator = ImageLocator.new(MountableImageServer.config.sources)
9
9
 
10
+ begin
11
+ respond_with_image(locator, fid, params)
12
+ rescue Skeptick::ImageMagickError => e
13
+ if e.message.include?('convert: unable to open image')
14
+ respond_with_image(locator, fid, params)
15
+ else
16
+ halt(404)
17
+ end
18
+ end
19
+ end
20
+
21
+ private
22
+ def respond_with_image(locator, fid, params)
10
23
  if path = locator.path_for(fid)
11
24
  image_processor = ImageProcessor.new(path, params)
12
25
 
@@ -1,3 +1,3 @@
1
1
  module MountableImageServer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "minitest", "~> 5.0"
25
25
  spec.add_development_dependency "rack-test", "~> 0.6.3"
26
26
 
27
- spec.add_runtime_dependency "sinatra", "~> 1.4.5"
27
+ spec.add_runtime_dependency "sinatra", "~> 2.0.0.rc1"
28
28
  spec.add_runtime_dependency "dry-configurable", "~> 0.1.6"
29
29
  spec.add_runtime_dependency "skeptick", "~> 0.2.1"
30
30
  end
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.1.0
4
+ version: 0.2.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: 2016-08-02 00:00:00.000000000 Z
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.4.5
75
+ version: 2.0.0.rc1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.4.5
82
+ version: 2.0.0.rc1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: dry-configurable
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +116,7 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
+ - ".ruby-version"
119
120
  - ".travis.yml"
120
121
  - Gemfile
121
122
  - LICENSE.txt
@@ -123,6 +124,7 @@ files:
123
124
  - Rakefile
124
125
  - bin/console
125
126
  - bin/setup
127
+ - config.ru
126
128
  - lib/mountable_image_server.rb
127
129
  - lib/mountable_image_server/image_locator.rb
128
130
  - lib/mountable_image_server/image_processor.rb
@@ -149,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
151
  version: '0'
150
152
  requirements: []
151
153
  rubyforge_project:
152
- rubygems_version: 2.4.5
154
+ rubygems_version: 2.5.1
153
155
  signing_key:
154
156
  specification_version: 4
155
157
  summary: Simple mountable server for processing images on the fly.