dynamic_image 2.0.0.beta4 → 2.0.0.beta5

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: 13ff169ce75c97a2fd1c4f6e5ed7f4236ca7c427
4
- data.tar.gz: 289506e149b4e4b8a1141e31767f885174a765d6
3
+ metadata.gz: cd6783a5824c2de5a61c549f88613c5461779e9b
4
+ data.tar.gz: f1f6a7b013b1ec0a0bdac1dd1dcd48fc72305112
5
5
  SHA512:
6
- metadata.gz: a05f6fb62543baa9d489ccf47aebb308513db35aaf374eedbfeb91252b844ace7cc00bd289be5c2ff13b893ea481b73103ded631837f9582a00fe61714f3a5f0
7
- data.tar.gz: 4acdbae86426d975ceed4ca44369303bbec92a6c5c757d4a3960f035ff19bd5313626783a01c3fd00b257c3a82a4659c4729a90d79c3d318bc1b94881622f6b0
6
+ metadata.gz: 0f1a9443802ed6be61bd135800c748a85da7b2c72cc3bf3a832a21ac91f3c02bce47aec16e0a259b5fbd3ba7bccef78e5ba4c7b3063dfc752dbf08d09384ed7b
7
+ data.tar.gz: eb357b816a71f5b6e3d58a851bbdfd9795d75ba91a5f8629c7922fcc929e203bcc3c8970d1f9c04b23fff0a5ac40db37883fb8b17f4d63fdf0b8e93a172d84c7
data/README.md CHANGED
@@ -48,33 +48,33 @@ that the generated URLs are properly signed and timestamped.
48
48
  To display the image at it's original size, use `dynamic_image_tag` without
49
49
  any options.
50
50
 
51
- ```html
51
+ ```erb
52
52
  <%= dynamic_image_tag image %>
53
53
  ```
54
54
 
55
55
  To resize it, specify a max size. This will scale the image down to fit, but
56
56
  no cropping will occur.
57
57
 
58
- ```html
58
+ ```erb
59
59
  <%= dynamic_image_tag image, size: '400x400' %>
60
60
  ```
61
61
 
62
62
  Setting `crop: true` will crop the image to the exact size.
63
63
 
64
- ```html
64
+ ```erb
65
65
  <%= dynamic_image_tag image, size: '400x400', crop: true %>
66
66
  ```
67
67
 
68
68
  Omitting either dimension will render the image at an exact width or height.
69
69
 
70
- ```html
70
+ ```erb
71
71
  <%= dynamic_image_tag image, size: '400x' %>
72
72
  ```
73
73
 
74
74
  `dynamic_image_path` and `dynamic_image_url` act pretty much like regular URL
75
75
  helpers.
76
76
 
77
- ```html
77
+ ```erb
78
78
  <%= link_to "See image", dynamic_image_path(image) %>
79
79
  ```
80
80
 
@@ -83,4 +83,4 @@ helpers.
83
83
  Copyright 2006-2014 Inge Jørgensen
84
84
 
85
85
  DynamicImage is released under the
86
- [MIT License](http://www.opensource.org/licenses/MIT).
86
+ [MIT License](http://www.opensource.org/licenses/MIT).
@@ -43,6 +43,7 @@ module DynamicImage
43
43
  end
44
44
  end
45
45
 
46
+ # Returns the requested size as a vector.
46
47
  def requested_size
47
48
  Vector2d.parse(params[:size])
48
49
  end
@@ -38,9 +38,6 @@ module DynamicImage
38
38
  normalized do |image|
39
39
  image.crop image_sizing.crop_geometry_string(size)
40
40
  image.resize size
41
- if content_type == 'image/gif'
42
- image.coalesce
43
- end
44
41
  end
45
42
  end
46
43
 
@@ -49,6 +46,7 @@ module DynamicImage
49
46
  # * Applies EXIF rotation
50
47
  # * CMYK images are converted to sRGB
51
48
  # * Strips metadata
49
+ # * Optimizes GIFs
52
50
  # * Performs format conversion if the requested format is different
53
51
  #
54
52
  # ==== Example
@@ -61,10 +59,10 @@ module DynamicImage
61
59
  require_valid_image!
62
60
  process_data do |image|
63
61
  image.combine_options do |combined|
64
- image.auto_orient
65
- image.colorspace('sRGB') if needs_colorspace_conversion?
62
+ combined.auto_orient
63
+ combined.colorspace('sRGB') if needs_colorspace_conversion?
66
64
  yield(combined) if block_given?
67
- image.strip
65
+ optimize(combined)
68
66
  end
69
67
  image.format(format) if needs_format_conversion?
70
68
  end
@@ -72,10 +70,22 @@ module DynamicImage
72
70
 
73
71
  private
74
72
 
73
+ def coalesced(image)
74
+ if gif?
75
+ image.coalesce
76
+ image = MiniMagick::Image.read(image.to_blob)
77
+ end
78
+ image
79
+ end
80
+
75
81
  def format
76
82
  @format || record_format
77
83
  end
78
84
 
85
+ def gif?
86
+ content_type == 'image/gif'
87
+ end
88
+
79
89
  def image_sizing
80
90
  @image_sizing ||= DynamicImage::ImageSizing.new(record, uncropped: @uncropped)
81
91
  end
@@ -88,8 +98,15 @@ module DynamicImage
88
98
  format != record_format
89
99
  end
90
100
 
101
+ def optimize(image)
102
+ if gif?
103
+ image.layers 'optimize'
104
+ end
105
+ image.strip
106
+ end
107
+
91
108
  def process_data(&block)
92
- image = MiniMagick::Image.read(record.data)
109
+ image = coalesced(MiniMagick::Image.read(record.data))
93
110
  yield(image)
94
111
  result = image.to_blob
95
112
  image.destroy!
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module DynamicImage
4
- VERSION = "2.0.0.beta4"
4
+ VERSION = "2.0.0.beta5"
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.beta4
4
+ version: 2.0.0.beta5
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-02 00:00:00.000000000 Z
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails