dynamic_image 2.0.0.beta5 → 2.0.0.beta6

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: cd6783a5824c2de5a61c549f88613c5461779e9b
4
- data.tar.gz: f1f6a7b013b1ec0a0bdac1dd1dcd48fc72305112
3
+ metadata.gz: 051d5b39accd268d9cc110266aedd9fdb8f1cdd1
4
+ data.tar.gz: b1269f69f608a7bc858b508bbfebdb307af95bed
5
5
  SHA512:
6
- metadata.gz: 0f1a9443802ed6be61bd135800c748a85da7b2c72cc3bf3a832a21ac91f3c02bce47aec16e0a259b5fbd3ba7bccef78e5ba4c7b3063dfc752dbf08d09384ed7b
7
- data.tar.gz: eb357b816a71f5b6e3d58a851bbdfd9795d75ba91a5f8629c7922fcc929e203bcc3c8970d1f9c04b23fff0a5ac40db37883fb8b17f4d63fdf0b8e93a172d84c7
6
+ metadata.gz: 02c062771c93bbfde82f595c4410450c3934502de7fa042a51692bd55614fd3b51c3a31ed0eece6aeb22efa94df4d49f3fa0a645164d2b73e6101403ef0561d8
7
+ data.tar.gz: bab5fd5bd153d5a6181d8e8fccba6a8f484c390e04567d9b24a8052b13f4bcf9f52850eff7b5c0e9ac052e47b84c2266724874319f2a2eaf20d7839bfaebba88
data/README.md CHANGED
@@ -1,6 +1,33 @@
1
1
  # DynamicImage [![Build Status](https://travis-ci.org/elektronaut/dynamic_image.png)](https://travis-ci.org/elektronaut/dynamic_image) [![Code Climate](https://codeclimate.com/github/elektronaut/dynamic_image.png)](https://codeclimate.com/github/elektronaut/dynamic_image) [![Code Climate](https://codeclimate.com/github/elektronaut/dynamic_image/coverage.png)](https://codeclimate.com/github/elektronaut/dynamic_image)
2
2
 
3
- Requires Rails 4.1+ and Ruby 1.9.3+.
3
+ Need to handle image uploads in your Rails app?
4
+ Give DynamicImage a try.
5
+
6
+ Rather than creating a pre-defined set of images when a file is
7
+ uploaded, DynamicImage stores the original file and generates images
8
+ on demand. It handles cropping, resizing, format and colorspace
9
+ conversion.
10
+
11
+ Supported formats at the moment are JPEG, PNG, GIF and TIFF. The
12
+ latter will automatically be converted to JPG. CMYK images will be
13
+ converted to RGB, and RGB images will be converted to the sRGB
14
+ colorspace for consistent appearance in all browsers.
15
+
16
+ DynamicImage is built on [Dis](https://github.com/elektronaut/dis)
17
+ and [MiniMagick](https://github.com/minimagick/minimagick).
18
+
19
+ All URLs are signed with a HMAC to protect against denial of service
20
+ and enumeration attacks.
21
+
22
+ ## Requirements
23
+
24
+ * Rails 4.2
25
+ * Ruby 1.9.3+
26
+ * ImageMagick command line tools
27
+
28
+ ## Documentation
29
+
30
+ [Documentation is available on RubyDoc.info](http://rdoc.info/gems/dynamic_image)
4
31
 
5
32
  ## Installation
6
33
 
@@ -40,6 +67,15 @@ declaration.
40
67
  image_resources :images, path: "dynamic_images/:digest(/:size)"
41
68
  ```
42
69
 
70
+ ## Storing an image
71
+
72
+ To save an image, simply assign the file attribute to your uploaded file.
73
+
74
+ ```ruby
75
+ image_params = params.require(:image).permit(:file)
76
+ Image.create(image_params)
77
+ ```
78
+
43
79
  ## Rendering images in your views
44
80
 
45
81
  You should use the provided helpers for displaying images, this will ensure
@@ -49,26 +85,26 @@ To display the image at it's original size, use `dynamic_image_tag` without
49
85
  any options.
50
86
 
51
87
  ```erb
52
- <%= dynamic_image_tag image %>
88
+ <%= dynamic_image_tag(image) %>
53
89
  ```
54
90
 
55
91
  To resize it, specify a max size. This will scale the image down to fit, but
56
92
  no cropping will occur.
57
93
 
58
94
  ```erb
59
- <%= dynamic_image_tag image, size: '400x400' %>
95
+ <%= dynamic_image_tag(image, size: '400x400') %>
60
96
  ```
61
97
 
62
98
  Setting `crop: true` will crop the image to the exact size.
63
99
 
64
100
  ```erb
65
- <%= dynamic_image_tag image, size: '400x400', crop: true %>
101
+ <%= dynamic_image_tag(image, size: '400x400', crop: true) %>
66
102
  ```
67
103
 
68
104
  Omitting either dimension will render the image at an exact width or height.
69
105
 
70
106
  ```erb
71
- <%= dynamic_image_tag image, size: '400x' %>
107
+ <%= dynamic_image_tag(image, size: '400x') %>
72
108
  ```
73
109
 
74
110
  `dynamic_image_path` and `dynamic_image_url` act pretty much like regular URL
@@ -78,6 +114,22 @@ helpers.
78
114
  <%= link_to "See image", dynamic_image_path(image) %>
79
115
  ```
80
116
 
117
+ ## Caching
118
+
119
+ Generating images on the fly is expensive. This is less of a problem
120
+ in development mode, as DynamicImage respects the If-Modified-Since
121
+ header. In production, you should absolutely cache the results.
122
+
123
+ DynamicImage doesn't do any caching on it's own, but it is designed to
124
+ play well with others. Here's a few options:
125
+
126
+ * [CloudFlare](https://www.cloudflare.com)
127
+ * [Rack::Cache](http://rtomayko.github.io/rack-cache/)
128
+ * [actionpack-page_caching](https://github.com/rails/actionpack-page_caching)
129
+
130
+ It's perfectly safe to cache images indefinitely. The URL is
131
+ timestamped, and will change if the object changes.
132
+
81
133
  ## License
82
134
 
83
135
  Copyright 2006-2014 Inge Jørgensen
@@ -14,7 +14,6 @@ module DynamicImage
14
14
  before_action :verify_signed_params
15
15
  before_action :find_record
16
16
  after_action :cache_expiration_header
17
- respond_to :html, :gif, :jpeg, :png, :tiff
18
17
  helper_method :requested_size
19
18
  end
20
19
 
@@ -31,7 +30,7 @@ module DynamicImage
31
30
  # Renders the original image data, without any processing.
32
31
  def original
33
32
  if stale?(@record)
34
- respond_with(@record) do |format|
33
+ respond_to do |format|
35
34
  format.any(:gif, :jpeg, :png, :tiff) do
36
35
  send_data(
37
36
  @record.data,
@@ -61,7 +60,7 @@ module DynamicImage
61
60
  def render_image(options)
62
61
  processed_image = DynamicImage::ProcessedImage.new(@record, options)
63
62
  if stale?(@record)
64
- respond_with(@record) do |format|
63
+ respond_to do |format|
65
64
  format.html do
66
65
  render(file: File.join(File.dirname(__FILE__), 'templates/show'),
67
66
  layout: false, locals: {options: options})
@@ -30,7 +30,7 @@ module DynamicImage
30
30
  # dynamic_image_tag(image, size: "100x100", alt="Avatar")
31
31
  # # => <img alt="Avatar" height="62" src="..." width="100" />
32
32
  def dynamic_image_tag(record_or_array, options={})
33
- record = extract_record(record_or_array)
33
+ record = extract_dynamic_image_record(record_or_array)
34
34
  options = {
35
35
  alt: image_alt(record.filename)
36
36
  }.merge(options)
@@ -130,7 +130,7 @@ module DynamicImage
130
130
  end
131
131
 
132
132
  def dynamic_image_url_with_size(record_or_array, size=nil, options={})
133
- record = extract_record(record_or_array)
133
+ record = extract_dynamic_image_record(record_or_array)
134
134
  options = {
135
135
  routing_type: :url,
136
136
  action: nil,
@@ -141,8 +141,17 @@ module DynamicImage
141
141
  polymorphic_url(record_or_array, options)
142
142
  end
143
143
 
144
+ def extract_dynamic_image_record(record_or_array)
145
+ case record_or_array
146
+ when Array
147
+ record_or_array.last
148
+ else
149
+ record_or_array
150
+ end
151
+ end
152
+
144
153
  def fit_size!(record_or_array, options)
145
- record = extract_record(record_or_array)
154
+ record = extract_dynamic_image_record(record_or_array)
146
155
  action = options[:action].try(:to_s)
147
156
  size_opts = options.extract!(:size, :crop, :upscale)
148
157
 
@@ -151,10 +160,10 @@ module DynamicImage
151
160
  record,
152
161
  uncropped: (action == "uncropped")
153
162
  ).fit(size_opts[:size], size_opts).floor.to_s
154
- elsif action != "original"
155
- record.size.floor.to_s
163
+ elsif action == "original"
164
+ record.real_size.floor.to_s
156
165
  else
157
- nil
166
+ record.size.floor.to_s
158
167
  end
159
168
  end
160
169
  end
@@ -10,7 +10,7 @@ module DynamicImage
10
10
  @record = record
11
11
  @uncropped = options[:uncropped] ? true : false
12
12
  @format = options[:format].to_s.upcase if options[:format]
13
- @format = "JPEG" if @format == "JPG"
13
+ @format = "JPEG" if defined?(@format) && @format == "JPG"
14
14
  end
15
15
 
16
16
  # Returns the content type of the processed image.
@@ -79,7 +79,7 @@ module DynamicImage
79
79
  end
80
80
 
81
81
  def format
82
- @format || record_format
82
+ @format ||= record_format
83
83
  end
84
84
 
85
85
  def gif?
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module DynamicImage
4
- VERSION = "2.0.0.beta5"
4
+ VERSION = "2.0.0.beta6"
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.0.beta5
4
+ version: 2.0.0.beta6
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: 2014-12-04 00:00:00.000000000 Z
11
+ date: 2015-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.0
19
+ version: 4.2.0
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: 4.1.0
26
+ version: 4.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: vector2d
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 0.9.0
67
+ version: 1.0.0
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 0.9.0
74
+ version: 1.0.0
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: sqlite3
77
77
  requirement: !ruby/object:Gem::Requirement