paperclip-facecrop 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/lib/detectors/face_com.rb +0 -0
- data/lib/face_crop.rb +2 -1
- data/lib/processor.rb +19 -3
- data/lib/railtie.rb +2 -2
- data/paperclip-facecrop.gemspec +1 -1
- metadata +39 -30
data/.gitignore
CHANGED
data/lib/detectors/face_com.rb
CHANGED
File without changes
|
data/lib/face_crop.rb
CHANGED
data/lib/processor.rb
CHANGED
@@ -19,6 +19,7 @@ module Paperclip
|
|
19
19
|
def initialize(file, options = {}, attachment = nil)
|
20
20
|
super(file, options, attachment)
|
21
21
|
|
22
|
+
|
22
23
|
raise "No detectors were defined" if @@detectors.nil?
|
23
24
|
|
24
25
|
faces_regions = []
|
@@ -28,10 +29,12 @@ module Paperclip
|
|
28
29
|
begin
|
29
30
|
faces_regions += detector.detect(file.path)
|
30
31
|
rescue Exception => e
|
32
|
+
puts e
|
31
33
|
Rails.logger.error(e)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
37
|
+
|
35
38
|
x_coords, y_coords, widths, heights = [], [], [], []
|
36
39
|
|
37
40
|
faces_regions.each do |region|
|
@@ -41,6 +44,7 @@ module Paperclip
|
|
41
44
|
heights << region.height
|
42
45
|
end
|
43
46
|
|
47
|
+
|
44
48
|
@has_faces = faces_regions.size > 0
|
45
49
|
|
46
50
|
if @has_faces
|
@@ -50,6 +54,7 @@ module Paperclip
|
|
50
54
|
@bottom_right_y = y_coords.max
|
51
55
|
|
52
56
|
|
57
|
+
|
53
58
|
#puts @top_left_x.to_s
|
54
59
|
|
55
60
|
# average faces areas
|
@@ -63,6 +68,8 @@ module Paperclip
|
|
63
68
|
@top_left_x -= average_face_width / 1.2
|
64
69
|
@bottom_right_x += average_face_width / 1.2
|
65
70
|
|
71
|
+
|
72
|
+
|
66
73
|
# new height
|
67
74
|
#puts ":::#{@top_left_x}---#{average_face_width}"
|
68
75
|
#return
|
@@ -72,6 +79,8 @@ module Paperclip
|
|
72
79
|
|
73
80
|
calculate_bounds
|
74
81
|
|
82
|
+
|
83
|
+
|
75
84
|
# if the new area is smaller than the target geometry, it's scaled so the final image isn't resampled
|
76
85
|
#
|
77
86
|
if @faces_width < @target_geometry.width
|
@@ -80,7 +89,13 @@ module Paperclip
|
|
80
89
|
@bottom_right_x += delta_width
|
81
90
|
calculate_bounds
|
82
91
|
end
|
83
|
-
|
92
|
+
|
93
|
+
# scale the image so the cropped image still displays the faces
|
94
|
+
if @faces_width > @target_geometry.width && crop?
|
95
|
+
ratio = @faces_width / @target_geometry.width
|
96
|
+
@faces_height = @target_geometry.height * ratio
|
97
|
+
end
|
98
|
+
|
84
99
|
#raise (@target_geometry.height > 0 and @faces_height < @target_geometry.height).to_s
|
85
100
|
|
86
101
|
if (@target_geometry.height > 0 and @faces_height < @target_geometry.height)
|
@@ -89,7 +104,7 @@ module Paperclip
|
|
89
104
|
@bottom_right_y += delta_height
|
90
105
|
calculate_bounds
|
91
106
|
end
|
92
|
-
|
107
|
+
|
93
108
|
@faces_height = @faces_width if @target_geometry.height == 0
|
94
109
|
|
95
110
|
@current_geometry = Paperclip::Geometry.new(@faces_width, @faces_height)
|
@@ -116,11 +131,12 @@ module Paperclip
|
|
116
131
|
|
117
132
|
scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
|
118
133
|
faces_crop = "%dx%d+%d+%d" % [@faces_width, @faces_height, @top_left_x, @top_left_y]
|
119
|
-
|
134
|
+
|
120
135
|
trans = []
|
121
136
|
trans << "-crop" << %["#{faces_crop}"] << "+repage"
|
122
137
|
trans << "-resize" << %["#{scale}"] unless scale.nil? || scale.empty?
|
123
138
|
trans << "-crop" << %["#{crop}"] << "+repage" if crop
|
139
|
+
|
124
140
|
trans
|
125
141
|
end
|
126
142
|
|
data/lib/railtie.rb
CHANGED
@@ -3,7 +3,7 @@ module FaceCrop
|
|
3
3
|
initializer "paperclip-facecrop.extend_has_attachment" do
|
4
4
|
raise "Paperclip needed" unless defined?(Paperclip)
|
5
5
|
ActiveSupport.on_load :active_record do
|
6
|
-
|
6
|
+
|
7
7
|
class ActiveRecord::Base
|
8
8
|
|
9
9
|
class << self
|
@@ -14,7 +14,7 @@ module FaceCrop
|
|
14
14
|
|
15
15
|
alias_method_chain :has_attached_file, :face_crop_cache
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
data/paperclip-facecrop.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "paperclip-facecrop"
|
6
|
-
s.version = "0.1.
|
6
|
+
s.version = "0.1.2"
|
7
7
|
s.authors = ["Borja Martín"]
|
8
8
|
s.description = %q{Paperclip processor that is aware of the faces detected on the image so that they don't get cropped or aren't shown too small while generating the thumbnails}
|
9
9
|
s.summary = %q{Paperclip processor that is aware of the faces found on the image}
|
metadata
CHANGED
@@ -1,34 +1,38 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-facecrop
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 0.1.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
- Borja
|
7
|
+
authors:
|
8
|
+
- "Borja Mart\xC3\xADn"
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
date: 2011-08-17 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
15
17
|
name: paperclip
|
16
|
-
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
20
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
22
25
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
description: Paperclip processor that is aware of the faces detected on the image
|
26
|
-
so that they don't get cropped or aren't shown too small while generating the thumbnails
|
26
|
+
version_requirements: *id001
|
27
|
+
description: Paperclip processor that is aware of the faces detected on the image so that they don't get cropped or aren't shown too small while generating the thumbnails
|
27
28
|
email: borjam@dagi3d.net
|
28
29
|
executables: []
|
30
|
+
|
29
31
|
extensions: []
|
32
|
+
|
30
33
|
extra_rdoc_files: []
|
31
|
-
|
34
|
+
|
35
|
+
files:
|
32
36
|
- .gitignore
|
33
37
|
- Gemfile
|
34
38
|
- README.md
|
@@ -43,28 +47,33 @@ files:
|
|
43
47
|
- lib/processor.rb
|
44
48
|
- lib/railtie.rb
|
45
49
|
- paperclip-facecrop.gemspec
|
50
|
+
has_rdoc: true
|
46
51
|
homepage: http://github.com/dagi3d/paperclip-facecrop
|
47
52
|
licenses: []
|
53
|
+
|
48
54
|
post_install_message:
|
49
55
|
rdoc_options: []
|
50
|
-
|
56
|
+
|
57
|
+
require_paths:
|
51
58
|
- lib
|
52
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
60
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version:
|
58
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
66
|
none: false
|
60
|
-
requirements:
|
61
|
-
- -
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version:
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
64
71
|
requirements: []
|
72
|
+
|
65
73
|
rubyforge_project:
|
66
|
-
rubygems_version: 1.
|
74
|
+
rubygems_version: 1.6.2
|
67
75
|
signing_key:
|
68
76
|
specification_version: 3
|
69
77
|
summary: Paperclip processor that is aware of the faces found on the image
|
70
78
|
test_files: []
|
79
|
+
|