dynamic_image 2.0.18 → 2.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/dynamic_image/belongs_to.rb +1 -1
- data/lib/dynamic_image/controller.rb +2 -2
- data/lib/dynamic_image/engine.rb +11 -1
- data/lib/dynamic_image/image_reader.rb +2 -1
- data/lib/dynamic_image/image_sizing.rb +2 -2
- data/lib/dynamic_image/model/dimensions.rb +2 -2
- data/lib/dynamic_image/model/validations.rb +2 -1
- data/lib/dynamic_image/processed_image.rb +32 -30
- data/lib/dynamic_image/profiles/sRGB_ICC_v4_Appearance.icc +0 -0
- data/lib/dynamic_image/version.rb +1 -1
- metadata +38 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a9eeb1b5378e17d2dcf9d6c0245df5386a1253dfdbefd0fff61fd5faeb2a1ee
|
4
|
+
data.tar.gz: 3156acfe1931d9530dc5c23d51716904feb2f1f16f00657cd9aa52c61d97cf94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3c0d2fd1e238b181b8d7cd86ebb12c65ebbe37e606bf434c969584def13b968e0bbd66b845b553d65c7d8e9245f20a066b88ee66f523de87391adf285aa194a
|
7
|
+
data.tar.gz: 51eda1715d2eb18931256018f95dfe9f714817bda16601d5c1ded50778cc4a0a31d27ec00ffe3287a88205e1c49cea09c0d159594c8552a2a94084821ff403c1
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
[![Version](https://img.shields.io/gem/v/dynamic_image.svg?style=flat)](https://rubygems.org/gems/dynamic_image)
|
2
|
-
|
2
|
+
![Build](https://github.com/elektronaut/dynamic_image/workflows/Build/badge.svg)
|
3
3
|
[![Code Climate](https://codeclimate.com/github/elektronaut/dynamic_image/badges/gpa.svg)](https://codeclimate.com/github/elektronaut/dynamic_image)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/elektronaut/dynamic_image/badges/coverage.svg)](https://codeclimate.com/github/elektronaut/dynamic_image)
|
5
5
|
[![Inline docs](http://inch-ci.org/github/elektronaut/dynamic_image.svg)](http://inch-ci.org/github/elektronaut/dynamic_image)
|
@@ -15,9 +15,9 @@ uploaded, DynamicImage stores the original file and generates images
|
|
15
15
|
on demand. It handles cropping, resizing, format and colorspace
|
16
16
|
conversion.
|
17
17
|
|
18
|
-
Supported formats at the moment are JPEG, PNG, GIF, BMP and TIFF.
|
19
|
-
|
20
|
-
converted to RGB, and RGB images will be converted to the sRGB
|
18
|
+
Supported formats at the moment are JPEG, PNG, GIF, BMP, WebP and TIFF.
|
19
|
+
BMP, WebP and TIFF images will automatically be converted to JPG. CMYK
|
20
|
+
images will be converted to RGB, and RGB images will be converted to the sRGB
|
21
21
|
colorspace for consistent appearance in all browsers.
|
22
22
|
|
23
23
|
DynamicImage is built on [Dis](https://github.com/elektronaut/dis)
|
@@ -8,7 +8,7 @@ module DynamicImage
|
|
8
8
|
|
9
9
|
module ClassMethods
|
10
10
|
def belongs_to_image(name, scope = nil, **options)
|
11
|
-
belongs_to(name, scope, options)
|
11
|
+
belongs_to(name, scope, **options)
|
12
12
|
|
13
13
|
define_method "#{name}=" do |new_image|
|
14
14
|
if new_image.present? && !new_image.is_a?(DynamicImage::Model)
|
@@ -59,7 +59,7 @@ module DynamicImage
|
|
59
59
|
render(file: File.join(File.dirname(__FILE__), "templates/show"),
|
60
60
|
layout: false, locals: { options: options })
|
61
61
|
end
|
62
|
-
format.any(:gif, :jpeg, :png, :tiff) do
|
62
|
+
format.any(:gif, :jpeg, :jpg, :png, :tiff, :webp) do
|
63
63
|
send_image(DynamicImage::ProcessedImage.new(@record, options))
|
64
64
|
end
|
65
65
|
end
|
@@ -69,7 +69,7 @@ module DynamicImage
|
|
69
69
|
return unless stale?(@record)
|
70
70
|
|
71
71
|
respond_to do |format|
|
72
|
-
format.any(:gif, :jpeg, :png, :tiff) do
|
72
|
+
format.any(:gif, :jpeg, :jpg, :png, :tiff, :webp) do
|
73
73
|
send_data(@record.data,
|
74
74
|
filename: filename,
|
75
75
|
content_type: @record.content_type,
|
data/lib/dynamic_image/engine.rb
CHANGED
@@ -17,11 +17,21 @@ module DynamicImage
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
initializer "dynamic_image.mime_types" do
|
21
|
+
Mime::Type.register "image/bmp", :bmp
|
22
|
+
Mime::Type.register "image/gif", :gif
|
23
|
+
Mime::Type.register "image/jpeg", :jpg
|
24
|
+
Mime::Type.register "image/jpeg", :jpeg
|
25
|
+
Mime::Type.register "image/png", :png
|
26
|
+
Mime::Type.register "image/tiff", :tiff
|
27
|
+
Mime::Type.register "image/webp", :webp
|
28
|
+
end
|
29
|
+
|
20
30
|
initializer "dynamic_image.extensions", before: :load_active_support do
|
21
31
|
ActiveSupport.on_load(:active_record) do
|
22
32
|
send :include, DynamicImage::BelongsTo
|
23
33
|
end
|
24
|
-
ActionDispatch::Routing::Mapper.
|
34
|
+
ActionDispatch::Routing::Mapper.include DynamicImage::Routing
|
25
35
|
|
26
36
|
ActionDispatch::ExceptionWrapper.rescue_responses.merge!(
|
27
37
|
"DynamicImage::Errors::InvalidSignature" => :unauthorized
|
@@ -43,7 +43,7 @@ module DynamicImage
|
|
43
43
|
# Normalizes the image.
|
44
44
|
#
|
45
45
|
# * Applies EXIF rotation
|
46
|
-
# *
|
46
|
+
# * Converts to sRGB
|
47
47
|
# * Strips metadata
|
48
48
|
# * Optimizes GIFs
|
49
49
|
# * Performs format conversion if the requested format is different
|
@@ -59,7 +59,7 @@ module DynamicImage
|
|
59
59
|
process_data do |image|
|
60
60
|
image.combine_options do |combined|
|
61
61
|
combined.auto_orient
|
62
|
-
combined
|
62
|
+
convert_to_srgb(image, combined)
|
63
63
|
yield(combined) if block_given?
|
64
64
|
optimize(combined)
|
65
65
|
end
|
@@ -70,27 +70,35 @@ module DynamicImage
|
|
70
70
|
private
|
71
71
|
|
72
72
|
def coalesced(image)
|
73
|
-
|
73
|
+
gif? ? DynamicImage::ImageReader.new(image.coalesce.to_blob).read : image
|
74
|
+
end
|
75
|
+
|
76
|
+
def convert_to_srgb(image, combined)
|
77
|
+
combined.profile(srgb_profile) if image.data["profiles"].present?
|
78
|
+
combined.colorspace("sRGB") if record.cmyk?
|
79
|
+
end
|
74
80
|
|
75
|
-
|
81
|
+
def create_variant(size)
|
82
|
+
record.variants.create(
|
83
|
+
variant_params(size).merge(filename: record.filename,
|
84
|
+
content_type: content_type,
|
85
|
+
data: crop_and_resize(size))
|
86
|
+
)
|
76
87
|
end
|
77
88
|
|
78
89
|
def crop_and_resize(size)
|
79
90
|
normalized do |image|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
91
|
+
next unless record.cropped? || size != record.size
|
92
|
+
|
93
|
+
image.crop(image_sizing.crop_geometry_string(size))
|
94
|
+
image.resize(size)
|
84
95
|
end
|
85
96
|
end
|
86
97
|
|
87
98
|
def find_or_create_variant(size)
|
88
|
-
record.variants.find_by(variant_params(size)) ||
|
89
|
-
|
90
|
-
|
91
|
-
content_type: content_type,
|
92
|
-
data: crop_and_resize(size))
|
93
|
-
)
|
99
|
+
record.variants.find_by(variant_params(size)) || create_variant(size)
|
100
|
+
rescue ActiveRecord::RecordNotUnique
|
101
|
+
record.variants.find_by(variant_params(size))
|
94
102
|
end
|
95
103
|
|
96
104
|
def format
|
@@ -110,10 +118,6 @@ module DynamicImage
|
|
110
118
|
DynamicImage::ImageSizing.new(record, uncropped: @uncropped)
|
111
119
|
end
|
112
120
|
|
113
|
-
def needs_colorspace_conversion?
|
114
|
-
record.cmyk?
|
115
|
-
end
|
116
|
-
|
117
121
|
def needs_format_conversion?
|
118
122
|
format != record_format
|
119
123
|
end
|
@@ -136,27 +140,25 @@ module DynamicImage
|
|
136
140
|
attr_reader :record
|
137
141
|
|
138
142
|
def record_format
|
139
|
-
{ "image/bmp" => "BMP",
|
140
|
-
"image/
|
141
|
-
"image/
|
142
|
-
"image/jpeg" => "JPEG",
|
143
|
-
"image/pjpeg" => "JPEG",
|
144
|
-
"image/tiff" => "TIFF" }[record.content_type]
|
143
|
+
{ "image/bmp" => "BMP", "image/png" => "PNG", "image/gif" => "GIF",
|
144
|
+
"image/jpeg" => "JPEG", "image/pjpeg" => "JPEG", "image/tiff" => "TIFF",
|
145
|
+
"image/webp" => "WEBP" }[record.content_type]
|
145
146
|
end
|
146
147
|
|
147
148
|
def require_valid_image!
|
148
149
|
raise DynamicImage::Errors::InvalidImage unless record.valid?
|
149
150
|
end
|
150
151
|
|
152
|
+
def srgb_profile
|
153
|
+
File.join(File.dirname(__FILE__), "profiles/sRGB_ICC_v4_Appearance.icc")
|
154
|
+
end
|
155
|
+
|
151
156
|
def variant_params(size)
|
152
157
|
crop_size, crop_start = image_sizing.crop_geometry(size)
|
153
158
|
|
154
|
-
{ width: size.x,
|
155
|
-
|
156
|
-
|
157
|
-
crop_height: crop_size.y,
|
158
|
-
crop_start_x: crop_start.x,
|
159
|
-
crop_start_y: crop_start.y,
|
159
|
+
{ width: size.x.round, height: size.y.round,
|
160
|
+
crop_width: crop_size.x, crop_height: crop_size.y,
|
161
|
+
crop_start_x: crop_start.x, crop_start_y: crop_start.y,
|
160
162
|
format: format }
|
161
163
|
end
|
162
164
|
end
|
Binary file
|
metadata
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.23
|
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:
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dis
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0.6
|
20
17
|
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: '1.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.6
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 1.0.6
|
30
27
|
- - "~>"
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: '1.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.6
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: mini_magick
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,6 +78,20 @@ dependencies:
|
|
78
78
|
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: 2.2.1
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rails-controller-testing
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
81
95
|
- !ruby/object:Gem::Dependency
|
82
96
|
name: rspec-rails
|
83
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,6 +106,20 @@ dependencies:
|
|
92
106
|
- - "~>"
|
93
107
|
- !ruby/object:Gem::Version
|
94
108
|
version: 3.7.0
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: simplecov
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 0.17.1
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 0.17.1
|
95
123
|
- !ruby/object:Gem::Dependency
|
96
124
|
name: sqlite3
|
97
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,6 +162,7 @@ files:
|
|
134
162
|
- lib/dynamic_image/model/validations.rb
|
135
163
|
- lib/dynamic_image/model/variants.rb
|
136
164
|
- lib/dynamic_image/processed_image.rb
|
165
|
+
- lib/dynamic_image/profiles/sRGB_ICC_v4_Appearance.icc
|
137
166
|
- lib/dynamic_image/routing.rb
|
138
167
|
- lib/dynamic_image/templates/show.html.erb
|
139
168
|
- lib/dynamic_image/version.rb
|
@@ -157,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
186
|
- !ruby/object:Gem::Version
|
158
187
|
version: '0'
|
159
188
|
requirements: []
|
160
|
-
rubygems_version: 3.
|
189
|
+
rubygems_version: 3.1.2
|
161
190
|
signing_key:
|
162
191
|
specification_version: 4
|
163
192
|
summary: Rails plugin that simplifies image uploading and processing
|