$f2['diff'] ? -1 : 1; }); $targetIm = imagecreatetruecolor(1920, 1080); $white = imagecolorallocate($targetIm, 255, 255, 255); imagefill($targetIm, 0, 0, $white); $i = 0; $faceDim = 120; $faceMargin = 20; $itemsPerRow = (int) 1080 / ($faceDim + $faceMargin); $maxDiff = sqrt(count($params) * 100); foreach($json['faces'] as $face) { $posX = $i % $itemsPerRow; $posY = (int) ($i / $itemsPerRow); $destX = $posX * ($faceDim + $faceMargin); $destY = $posY * ($faceDim + $faceMargin); imagecopyresampled ( $targetIm , $im , $destX , $destY , (int) $face['rect']['x'] , (int) $face['rect']['y'] , $faceDim , $faceDim , (int) $face['rect']['w'], (int) $face['rect']['h']); $score = ($face['diff'] / $maxDiff) * 255; // score on 0-100 -> 255 scale for color: $colorBg = imagecolorallocate($im, (int) $score, (int) 255 - $score, 0); imagettftext($targetIm, 12, 0, $destX, $destY + $faceDim + $faceMargin/1.2, $colorBg, "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", round($face['diff'],2)); $i++; } $im = $targetIm; /* foreach($json['faces'] as $face) { // Draw a rectangle in color representing score on params imagecolorallocate($im, 200,200,200); $total = 0; foreach($params as $param) { $total += $face[$param]; } $score = ($total / count($params)) * 2.55; // score on 0-100 -> 255 scale for color: $colorBg = imagecolorallocate($im, (int) 255 - $score, (int) $score, 0); //~ var_dump($face['rect']); //~ imagefilledrectangle($im, $face['rect']['x'], $face['rect']['y'], $face['rect']['x']+$face['rect']['width'], $face['rect']['y']+$face['rect']['height'], $colorBg); $face['rect']['x2'] = round($face['rect']['x'] + $face['rect']['w']); $face['rect']['y2'] = round($face['rect']['y'] + $face['rect']['h']); $face['rect']['x'] = round($face['rect']['x']); $face['rect']['y'] = round($face['rect']['y']); imagefilledrectangle($im, $face['rect']['x'], $face['rect']['y'], $face['rect']['x2'], $face['rect']['y2'], $colorBg); } $im = imagescale($im, 1920, 1080); */ header("Content-Type: image/jpeg"); // Save the image imagejpeg($im, NULL, 80); //~ imagedestroy($im);