Skip to content

Commit 80becfb

Browse files
committed
Added support for image resources + fixed more notices
1 parent 2016692 commit 80becfb

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

FaceDetector.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ public function __construct($detection_file = 'detection.dat') {
3535
}
3636

3737
public function face_detect($file) {
38-
if (!is_file($file)) {
38+
if (is_resource($file)) {
39+
$this->canvas = $file;
40+
}
41+
elseif (is_file($file)) {
42+
$this->canvas = imagecreatefromjpeg($file);
43+
}
44+
else {
3945
throw new Exception("Can not load $file");
4046
}
4147

42-
$this->canvas = imagecreatefromjpeg($file);
4348
$im_width = imagesx($this->canvas);
4449
$im_height = imagesy($this->canvas);
4550

@@ -59,9 +64,11 @@ public function face_detect($file) {
5964

6065
$stats = $this->get_img_stats($this->reduced_canvas);
6166
$this->face = $this->do_detect_greedy_big_to_small($stats['ii'], $stats['ii2'], $stats['width'], $stats['height']);
62-
$this->face['x'] *= $ratio;
63-
$this->face['y'] *= $ratio;
64-
$this->face['w'] *= $ratio;
67+
if ($this->face['w'] > 0) {
68+
$this->face['x'] *= $ratio;
69+
$this->face['y'] *= $ratio;
70+
$this->face['w'] *= $ratio;
71+
}
6572
} else {
6673
$stats = $this->get_img_stats($this->canvas);
6774
$this->face = $this->do_detect_greedy_big_to_small($stats['ii'], $stats['ii2'], $stats['width'], $stats['height']);

0 commit comments

Comments
 (0)