dynamic_image 2.0.24 → 2.1.3

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
  SHA256:
3
- metadata.gz: 6828f7825142e16348273c97f77cda19d191849ff09e545174c8bb445372257e
4
- data.tar.gz: 480ebd62de3ddf2a780971b1b63c1ef545dff59f7f54ee1f7ede5ebef33a485b
3
+ metadata.gz: 88946bb221af4be324495c5cbce15352b0dac30c805cc26539278849c84203c7
4
+ data.tar.gz: dec702cf571d58550096276cdd4149c2764f848755c57d5dd6dbed9d842f92e6
5
5
  SHA512:
6
- metadata.gz: 95279e2367c7f8639be599e3717fd815bcf4f482a59ab3bcafd1e51aac3ce7c86621a1f694a2dfced38473de1b73fde9e7396a085d7e0cc6a335270267ddccfb
7
- data.tar.gz: 62e6c9b6b440a51855ae1d5a89bb2b85fab6c126603aa5e0b08f58b372bf7007ddb3e5eb7c9d910a2bb0ee59a0fb217711e706e5adbdb19008f0e97d9ec67087
6
+ metadata.gz: f1a20baa94b4629f9a1772a745cb6a26910e9d01696d13df1678498449f0c0a7cd1f06c3a143b2f117b0ec340c84333063aaf59bbc4ca8b95e71a95f861a6726
7
+ data.tar.gz: fec483b01c6025ddb6c6037bbd6655fadc33516216d3d0f83945f7417a2418de53d8b0bdd53b34b768084b76cd7660893c36c6f50453a49a076a2e34061562c9
data/README.md CHANGED
@@ -31,6 +31,7 @@ and enumeration attacks.
31
31
  * Rails 5
32
32
  * Ruby 2.4+
33
33
  * ImageMagick command line tools
34
+ * ExifTool
34
35
 
35
36
  ## Documentation
36
37
 
data/lib/dynamic_image.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "mini_exiftool"
3
4
  require "mini_magick"
4
5
  require "dis"
5
6
  require "vector2d"
@@ -19,5 +20,5 @@ require "dynamic_image/processed_image"
19
20
  require "dynamic_image/routing"
20
21
 
21
22
  module DynamicImage
22
- cattr_accessor :digest_verifier
23
+ cattr_accessor :digest_verifier, :process_later_limit
23
24
  end
@@ -44,16 +44,33 @@ module DynamicImage
44
44
  private
45
45
 
46
46
  def cache_expiration_header
47
- expires_in 30.days, public: true if response.status == 200
47
+ expires_in 1.year, public: true if response.status == 200
48
48
  end
49
49
 
50
50
  def find_record
51
51
  @record = model.find(params[:id])
52
52
  end
53
53
 
54
+ def process_and_send(image, options)
55
+ processed_image = DynamicImage::ProcessedImage.new(image, options)
56
+ if process_later?(processed_image, requested_size)
57
+ process_later(image, options, requested_size)
58
+ head 503, retry_after: 10
59
+ else
60
+ send_image(processed_image, requested_size)
61
+ end
62
+ end
63
+
64
+ def process_later(image, options, requested_size)
65
+ DynamicImage::Jobs::CreateVariant
66
+ .perform_later(image, options, requested_size.to_s)
67
+ end
68
+
54
69
  def process_later?(processed_image, size)
70
+ return false unless DynamicImage.process_later_limit
71
+
55
72
  image_size = processed_image.record.size.x * processed_image.record.size.y
56
- image_size > 12_500_000 &&
73
+ image_size > DynamicImage.process_later_limit &&
57
74
  !processed_image.find_variant(size)
58
75
  end
59
76
 
@@ -66,7 +83,7 @@ module DynamicImage
66
83
  layout: false, locals: { options: options })
67
84
  end
68
85
  format.any(:gif, :jpeg, :jpg, :png, :tiff, :webp) do
69
- send_image(@record, options)
86
+ process_and_send(@record, options)
70
87
  end
71
88
  end
72
89
  end
@@ -88,17 +105,10 @@ module DynamicImage
88
105
  params[:format]
89
106
  end
90
107
 
91
- def send_image(image, options)
92
- processed_image = DynamicImage::ProcessedImage.new(image, options)
93
- if process_later?(processed_image, requested_size)
94
- DynamicImage::Jobs::CreateVariant
95
- .perform_later(image, options, requested_size.to_s)
96
- head 503, retry_after: 10
97
- else
98
- send_data(processed_image.cropped_and_resized(requested_size),
99
- content_type: processed_image.content_type,
100
- disposition: "inline")
101
- end
108
+ def send_image(processed_image, requested_size)
109
+ send_data(processed_image.cropped_and_resized(requested_size),
110
+ content_type: processed_image.content_type,
111
+ disposition: "inline")
102
112
  end
103
113
 
104
114
  def verify_signed_params
@@ -3,11 +3,17 @@
3
3
  module DynamicImage
4
4
  module Errors
5
5
  class Error < StandardError; end
6
+
6
7
  class InvalidImage < DynamicImage::Errors::Error; end
8
+
7
9
  class InvalidHeader < DynamicImage::Errors::Error; end
10
+
8
11
  class InvalidSignature < DynamicImage::Errors::Error; end
12
+
9
13
  class InvalidSizeOptions < DynamicImage::Errors::Error; end
14
+
10
15
  class InvalidTransformation < DynamicImage::Errors::Error; end
16
+
11
17
  class ParameterMissing < DynamicImage::Errors::Error; end
12
18
  end
13
19
  end
@@ -21,6 +21,12 @@ module DynamicImage
21
21
  @data = data
22
22
  end
23
23
 
24
+ def exif
25
+ raise DynamicImage::Errors::InvalidHeader unless valid_header?
26
+
27
+ MiniExiftool.new(string_io)
28
+ end
29
+
24
30
  def read
25
31
  raise DynamicImage::Errors::InvalidHeader unless valid_header?
26
32
 
@@ -39,7 +45,11 @@ module DynamicImage
39
45
  private
40
46
 
41
47
  def file_header
42
- @file_header ||= StringIO.new(@data, "rb").read(8)
48
+ @file_header ||= string_io.read(8)
49
+ end
50
+
51
+ def string_io
52
+ StringIO.new(@data, "rb")
43
53
  end
44
54
  end
45
55
  end
@@ -90,7 +90,10 @@ module DynamicImage
90
90
  end
91
91
 
92
92
  def convert_to_srgb(image, combined)
93
- combined.profile(srgb_profile) if image.data["profiles"].present?
93
+ if image.data["profiles"].present? &&
94
+ exif.colorspacedata&.strip&.downcase == record.colorspace
95
+ combined.profile(srgb_profile)
96
+ end
94
97
  combined.colorspace("sRGB") if record.cmyk?
95
98
  end
96
99
 
@@ -111,6 +114,10 @@ module DynamicImage
111
114
  end
112
115
  end
113
116
 
117
+ def exif
118
+ @exif ||= DynamicImage::ImageReader.new(record.data).exif
119
+ end
120
+
114
121
  def format
115
122
  @format ||= record_format
116
123
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DynamicImage
4
- VERSION = "2.0.24"
4
+ VERSION = "2.1.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_image
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.24
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Inge Jørgensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-27 00:00:00.000000000 Z
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dis
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.0.6
33
+ - !ruby/object:Gem::Dependency
34
+ name: mini_exiftool
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.10'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.10'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: mini_magick
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -96,16 +110,16 @@ dependencies:
96
110
  name: rspec-rails
97
111
  requirement: !ruby/object:Gem::Requirement
98
112
  requirements:
99
- - - "~>"
113
+ - - ">="
100
114
  - !ruby/object:Gem::Version
101
- version: 3.7.0
115
+ version: '0'
102
116
  type: :development
103
117
  prerelease: false
104
118
  version_requirements: !ruby/object:Gem::Requirement
105
119
  requirements:
106
- - - "~>"
120
+ - - ">="
107
121
  - !ruby/object:Gem::Version
108
- version: 3.7.0
122
+ version: '0'
109
123
  - !ruby/object:Gem::Dependency
110
124
  name: simplecov
111
125
  requirement: !ruby/object:Gem::Requirement
@@ -188,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
202
  - !ruby/object:Gem::Version
189
203
  version: '0'
190
204
  requirements: []
191
- rubygems_version: 3.1.2
205
+ rubygems_version: 3.1.4
192
206
  signing_key:
193
207
  specification_version: 4
194
208
  summary: Rails plugin that simplifies image uploading and processing