Class: BlurFaces

Inherits:
Object
  • Object
show all
Defined in:
lib/blurfaces.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fname = nil) ⇒ BlurFaces

Returns a new instance of BlurFaces.



13
14
15
16
17
18
# File 'lib/blurfaces.rb', line 13

def initialize(fname=nil)

  @df = DetectFaces.new
  read(fname) if fname 

end

Instance Attribute Details

#facesObject

Returns the value of attribute faces.



11
12
13
# File 'lib/blurfaces.rb', line 11

def faces
  @faces
end

Instance Method Details

#blur(strength: 8) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/blurfaces.rb', line 20

def blur(strength: 8)

  @faces.each do |x, y, width, height|

    region = @img.dispatch(x, y, width, height, 'RGB')
    face_img = Magick::Image.constitute(width, height, "RGB", region)

    @img.composite!(face_img.gaussian_blur(0, strength), x, y, 
      Magick::OverCompositeOp)

  end

end

#read(fname) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/blurfaces.rb', line 34

def read(fname)

  @fname = fname
  @faces = @df.read(fname).faces
  @img = Magick::Image.read(fname)[0]

  self

end

#save(fname) ⇒ Object



44
45
46
# File 'lib/blurfaces.rb', line 44

def save(fname)
  @img.write(fname)
end