api.emotionhero.com/www/faces.php

61 lines
1.6 KiB
PHP
Raw Normal View History

2016-09-14 12:33:15 +00:00
<?php
require __DIR__ . '/../bootstrap.php';
2016-09-14 15:34:01 +00:00
error_reporting(E_ALL);ini_set('display_errors', true);
2016-09-14 12:33:15 +00:00
$em = \EmotionHero\Application::getInstance()->getEm();
$hitRepo = $em->getRepository(\EmotionHero\Models\Hit::class);
2016-09-14 15:34:01 +00:00
$currentEmotion = 'anger';
$hits = $hitRepo->findBy([], ["emotions.$currentEmotion"=>'ASC']);
2016-09-14 12:33:15 +00:00
?>
<html>
<head>
<title>Emotion Hero</title>
</head>
<style type="text/css">
body{
background:yellow;
2016-09-14 15:34:01 +00:00
font-family:"Unifont";
font-weight:bold;
2016-09-14 12:33:15 +00:00
}
</style>
<body>
<?php
2016-09-14 15:34:01 +00:00
foreach(range(0, 100, 10) as $i) {
/* @var $hitRepo EmotionHero\Models\HitRepository */
$hitRepo = $em->getRepository(EmotionHero\Models\Hit::class);
2016-09-14 15:48:50 +00:00
$hit = $hitRepo->getClosestHitWithImage("anger", $i);
2016-09-14 15:35:14 +00:00
$img = $hit->getFeatureImgAsString("brows");
2016-09-14 15:34:01 +00:00
$score = $hit->getEmotions()->getEmotionScore("anger");
$percentage = sprintf("%.4f %%",$score);
echo <<< EOSNIPPET
<div class="block">
<span class="perc">$percentage</span>
<img src="data:image/x-icon;base64,$img" title='{$hit->getId()}'>
</div>
EOSNIPPET;
}
2016-09-14 12:33:15 +00:00
/* @var $hit EmotionHero\Models\Hit */
foreach($hits as $hit) {
$filename = __DIR__ . '/../files/hits/brows/'. $hit->getId() . '.jpg';
if(!file_exists($filename))
continue;
$img = file_get_contents($filename);
$data = base64_encode($img);
2016-09-14 15:34:01 +00:00
$percentage = sprintf("%.4f %%",$hit->getEmotions()->getEmotionScore($currentEmotion));
echo <<< EOSNIPPET
<div class="block">
<span class="perc">$percentage</span>
<img src="data:image/x-icon;base64,$data" title='{$hit->getId()}'>
</div>
EOSNIPPET;
2016-09-14 12:33:15 +00:00
}
?>
</body>
2016-09-14 15:34:01 +00:00
</html>