snapimage 0.0.3 → 0.0.4

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.
@@ -57,6 +57,10 @@ module SnapImage
57
57
  @image.to_blob
58
58
  end
59
59
 
60
+ def destroy!
61
+ @image.destroy!
62
+ end
63
+
60
64
  # Crops the image with the given parameters and returns a SnapImage::Image
61
65
  # object.
62
66
  #
@@ -120,7 +120,10 @@ module SnapImage
120
120
  width: @request.json["crop_width"],
121
121
  height: @request.json["crop_height"]
122
122
  }
123
- image = image.crop(crop[:x], crop[:y], crop[:width], crop[:height])
123
+ cropped_image = image.crop(crop[:x], crop[:y], crop[:width], crop[:height])
124
+ # Release memory.
125
+ image.destroy!
126
+ image = cropped_image
124
127
  end
125
128
 
126
129
  # Resize.
@@ -131,21 +134,34 @@ module SnapImage
131
134
  if width && height
132
135
  # When both width and height are specified, resize without
133
136
  # maintaining the aspect ratio.
134
- image = image.resize(width, height, false)
137
+ resized_image = image.resize(width, height, false)
135
138
  else
136
139
  # When only one of width/height is specified, set the other to the
137
140
  # max and maintain the aspect ratio.
138
- image = image.resize(width || @config["max_width"], height || @config["max_height"])
141
+ resized_image = image.resize(width || @config["max_width"], height || @config["max_height"])
139
142
  end
143
+ # Release memeory.
144
+ image.destroy!
145
+ image = resized_image
140
146
  end
141
147
 
142
148
  # Resize to fit.
143
149
  resized_to_fit = resize_to_fit?(image)
144
- image = image.resize(get_max_width, get_max_height) if resized_to_fit
150
+ if resized_to_fit
151
+ resized_image = image.resize(get_max_width, get_max_height)
152
+ # Release memeory.
153
+ image.destroy!
154
+ image = resized_image
155
+ end
145
156
 
146
157
  # Sharpen.
147
158
  sharpened = sharpen?
148
- image = image.sharpen if sharpened
159
+ if sharpened
160
+ sharpened_image = image.sharpen
161
+ # Release memeory.
162
+ image.destroy!
163
+ image = sharpened_image
164
+ end
149
165
 
150
166
  # Get the dimensions at the end.
151
167
  if cropped || resized || resized_to_fit || sharpened
@@ -102,6 +102,8 @@ module SnapImage
102
102
  resized_image = image.resize([image.width, @config["max_width"]].min, [image.height, @config["max_height"]].min)
103
103
  # Generate a new name.
104
104
  resized_name = SnapImage::ImageNameUtils.get_resized_image_name(name, resized_image.width, resized_image.height)
105
+ # Release memory.
106
+ image.destroy!
105
107
  end
106
108
  { image: resized_image || image, name: resized_name || name }
107
109
  end
@@ -1,3 +1,3 @@
1
1
  module SnapImage
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapimage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -222,7 +222,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
222
222
  version: '0'
223
223
  segments:
224
224
  - 0
225
- hash: -2291908559965815813
225
+ hash: 1856855700602355455
226
226
  required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  none: false
228
228
  requirements:
@@ -231,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
231
  version: '0'
232
232
  segments:
233
233
  - 0
234
- hash: -2291908559965815813
234
+ hash: 1856855700602355455
235
235
  requirements: []
236
236
  rubyforge_project:
237
237
  rubygems_version: 1.8.23