/** * The callback ran in the async request to do the face detection. * * @access private * @since 1.0 * @static * @param array $atts The associative array that is passed to an instance of cnImage::get() when processing an immage. * @param string $source The image URL or absolute path. NOTE: The onl valid pathhs will be: WP_CONTENT/UPLOADS or STYLESHEETPATH * @param string $return What to return, @see cnImage::get() * * @return void */ public static function detect($atts, $source, $return) { if (!is_wp_error($info = cnImage::info($source))) { $name = $info['basename']; $cache = cnCache::get('face_detect', 'option-cache', 'cnfc'); $image = $cache != FALSE ? json_decode($cache, TRUE) : array(); if ($image == FALSE || (!isset($image[$name]) || $image[$name]['modified'] != $info['modified'])) { if (!class_exists('svay\\FaceDetector')) { include_once CNFD_PATH . 'vendor/facedetector/FaceDetector.php'; } $detect = new svay\FaceDetector(); $detect->faceDetect($info['path']); $coord = $detect->getFace(); if (!is_null($coord)) { $atts['crop_focus'] = array(($coord['x'] + $coord['w'] / 2) / $info[0], $coord['y'] / $info[1]); } $image[$name]['path'] = $info['path']; $image[$name]['modified'] = $info['modified']; $image[$name]['mime'] = $info['mime']; $image[$name]['width'] = $info[0]; $image[$name]['height'] = $info[1]; $image[$name]['face'] = $coord; $image[$name]['crop_focus'] = $atts['crop_focus']; if (!is_wp_error($result = cnImage::get($source, $atts))) { cnCache::set('face_detect', json_encode($image), YEAR_IN_SECONDS, 'option-cache', 'cnfc'); } } } }
public function DetectFace() { $detector = new svay\FaceDetector(); $detector->faceDetect($this->owner->getFullPath()); return $detector->getFace(); }