carrierwave-vips 0.9.9 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/carrierwave/vips.rb +36 -12
  2. metadata +2 -2
@@ -36,6 +36,10 @@ module CarrierWave
36
36
  def convert(extension)
37
37
  process :convert => extension
38
38
  end
39
+
40
+ def strip
41
+ process :strip
42
+ end
39
43
  end
40
44
 
41
45
  ##
@@ -51,18 +55,30 @@ module CarrierWave
51
55
  image
52
56
  end
53
57
  end
54
-
58
+
59
+ ##
60
+ # Remove all exif and icc data when writing to a file. This method does
61
+ # not actually remove any metadata but rather marks it to be removed when
62
+ # writing the file.
63
+ #
64
+ def strip
65
+ manipulate! do |image|
66
+ @_strip = true
67
+ image
68
+ end
69
+ end
70
+
55
71
  ##
56
72
  # Convert the file to a different format
57
73
  #
58
74
  #
59
75
  # === Parameters
60
- # [f (String)] the format for the file format (jpeg, png, gif)
76
+ # [f (String)] the format for the file format (jpeg, png)
61
77
  # [opts (Hash)] options to be passed to converting function (ie, :interlace => true for png)
62
78
  #
63
79
  def convert(f, opts = {})
64
80
  f = f.to_s.downcase
65
- allowed = %w(jpeg png gif)
81
+ allowed = %w(jpeg png)
66
82
  raise ArgumentError, "Format must be one of: #{allowed.join(',')}" unless allowed.include?(f)
67
83
  @_format = f
68
84
  @_format_opts = opts
@@ -159,27 +175,35 @@ module CarrierWave
159
175
  @_vimage ||= VIPS::Image.new(current_path)
160
176
  @_vimage = yield @_vimage
161
177
  rescue => e
162
- raise CarrierWave::ProcessingError.new("Failed to manipulate file, maybe it is not an image? Original Error: #{e}")
178
+ raise CarrierWave::ProcessingError.new("Failed to manipulate file, maybe it is not a supported image? Original Error: #{e}")
163
179
  end
164
-
180
+
165
181
  def process!(*)
166
182
  ret = super
167
183
  if @_vimage
168
184
  tmp_name = current_path.sub(/(\.[a-z]+)$/i, '_tmp\1')
169
- if @_format
170
- @vimage.send(format, tmp_name, @_format_opts)
171
- else
172
- @_vimage.write(tmp_name)
185
+ writer = writer_class.send(:new, @_vimage, @_format_opts)
186
+ if @_strip
187
+ writer.remove_exif
188
+ writer.remove_icc
173
189
  end
190
+ writer.write(tmp_name)
174
191
  FileUtils.mv(tmp_name, current_path)
175
192
  @_vimage = nil
176
- @_format = nil
177
193
  end
178
194
  ret
179
195
  end
180
-
196
+
181
197
  private
182
-
198
+
199
+ def writer_class
200
+ case @_format
201
+ when 'jpeg' then VIPS::JPEGWriter
202
+ when 'png' then VIPS::PNGWriter
203
+ else VIPS::Writer
204
+ end
205
+ end
206
+
183
207
  def resize_image(image, width, height, min_or_max = :min)
184
208
  ratio = get_ratio image, width, height, min_or_max
185
209
  if jpeg? # find the shrink ratio for loading
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-vips
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-01 00:00:00.000000000 Z
12
+ date: 2012-08-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Adds VIPS support to CarrierWave
15
15
  email: eltiare@github.com