paperclip-facecrop 0.1.0 → 0.1.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/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  Gemfile.lock
4
+ .project
4
5
  .bundle
File without changes
@@ -20,7 +20,8 @@ module FaceCrop
20
20
  # detect
21
21
  #
22
22
  def detect(file)
23
- key = "#{self.class}#{file}"
23
+ key = "#{self.class}:" + Digest::MD5.hexdigest(File.read(file))
24
+
24
25
  regions = FaceCrop::Detector::Cache[key]
25
26
  return regions unless regions.nil?
26
27
 
@@ -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
 
@@ -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
@@ -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.0"
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 Martín
7
+ authors:
8
+ - "Borja Mart\xC3\xADn"
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-14 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
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
- requirement: &2153665720 !ruby/object:Gem::Requirement
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
17
20
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
22
25
  type: :runtime
23
- prerelease: false
24
- version_requirements: *2153665720
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
- files:
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
- require_paths:
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: '0'
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: '0'
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
64
71
  requirements: []
72
+
65
73
  rubyforge_project:
66
- rubygems_version: 1.8.6
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
+