Permalink
Browse files

Added support for image resources + fixed more notices

  • Loading branch information...
1 parent 2016692 commit 80becfba1b3fdefedaa8508f3d0e0f4cec76399f @bforchhammer bforchhammer committed Nov 11, 2011
Showing with 12 additions and 5 deletions.
  1. +12 −5 FaceDetector.php
View
@@ -35,11 +35,16 @@ public function __construct($detection_file = 'detection.dat') {
}
public function face_detect($file) {
- if (!is_file($file)) {
+ if (is_resource($file)) {
+ $this->canvas = $file;
+ }
+ elseif (is_file($file)) {
+ $this->canvas = imagecreatefromjpeg($file);
+ }
+ else {
throw new Exception("Can not load $file");
}
- $this->canvas = imagecreatefromjpeg($file);
$im_width = imagesx($this->canvas);
$im_height = imagesy($this->canvas);
@@ -59,9 +64,11 @@ public function face_detect($file) {
$stats = $this->get_img_stats($this->reduced_canvas);
$this->face = $this->do_detect_greedy_big_to_small($stats['ii'], $stats['ii2'], $stats['width'], $stats['height']);
- $this->face['x'] *= $ratio;
- $this->face['y'] *= $ratio;
- $this->face['w'] *= $ratio;
+ if ($this->face['w'] > 0) {
+ $this->face['x'] *= $ratio;
+ $this->face['y'] *= $ratio;
+ $this->face['w'] *= $ratio;
+ }
} else {
$stats = $this->get_img_stats($this->canvas);
$this->face = $this->do_detect_greedy_big_to_small($stats['ii'], $stats['ii2'], $stats['width'], $stats['height']);

0 comments on commit 80becfb

Please sign in to comment.