mm-attach-it 0.1.3 → 0.1.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.
@@ -21,10 +21,28 @@ class Storage
21
21
 
22
22
  def crop(new_width = nil, new_height = nil, filename = nil)
23
23
  new_image = Magick::Image.read(filename).first
24
+
25
+ geometry = resize_before_cropping(new_image, new_width, new_height)
26
+ new_image.change_geometry!(geometry) { |cols, rows, img| img.resize!(cols, rows) }
27
+
24
28
  width = new_image.columns
25
29
  height = new_image.rows
30
+
26
31
  new_image.crop!(width/2 - new_width/2, height/2 - new_height/2, new_width, new_height)
27
32
  new_image
28
33
  end
29
34
 
35
+ def resize_before_cropping(img = nil, new_width = nil, new_height = nil)
36
+ width = img.columns
37
+ height = img.rows
38
+
39
+ if width > height
40
+ "x#{new_height}>"
41
+ elsif (width < height)
42
+ "#{new_width.to_s}x>"
43
+ else
44
+ "#{new_width}x#{new_height}>"
45
+ end
46
+ end
47
+
30
48
  end
@@ -1,3 +1,3 @@
1
1
  module AttachIt
2
- Version = '0.1.3'
2
+ Version = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mm-attach-it
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adilson Chacon
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-26 00:00:00 Z
18
+ date: 2011-06-28 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: wand