has_images 0.2.1 → 0.2.2
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.
- data/lib/digineo/image.rb +24 -0
- metadata +3 -3
data/lib/digineo/image.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'RMagick'
|
1
2
|
class Digineo::Image < ActiveRecord::Base
|
2
3
|
|
3
4
|
set_table_name :digineo_images
|
@@ -61,6 +62,27 @@ class Digineo::Image < ActiveRecord::Base
|
|
61
62
|
save
|
62
63
|
end
|
63
64
|
|
65
|
+
def crop(params = {:style => :original})
|
66
|
+
|
67
|
+
args = [params[:x1].to_i, params[:y1].to_i, params[:width].to_i, params[:height].to_i]
|
68
|
+
|
69
|
+
if old_original = file.to_file(params[:style])
|
70
|
+
orig_img = Magick::ImageList.new
|
71
|
+
orig_img.from_blob(old_original.read)
|
72
|
+
orig_img.crop!(*args)
|
73
|
+
|
74
|
+
new_img = File.open(file.path(:original), "w")
|
75
|
+
new_img.write(orig_img.to_blob)
|
76
|
+
new_img.close
|
77
|
+
|
78
|
+
|
79
|
+
file.reprocess!
|
80
|
+
save
|
81
|
+
else
|
82
|
+
true
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
64
86
|
private
|
65
87
|
|
66
88
|
def should_be_avatar?
|
@@ -84,4 +106,6 @@ class Digineo::Image < ActiveRecord::Base
|
|
84
106
|
rescue # TODO catch url errors with validations instead of exceptions (Errno::ENOENT, OpenURI::HTTPError, etc...)
|
85
107
|
end
|
86
108
|
|
109
|
+
|
110
|
+
|
87
111
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_images
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dennis Meise
|