function serve($width, $height, $person) { $app = \Slim\Slim::getInstance(); $response = $app->response(); $response['Content-Type'] = 'image/jpeg'; $img = new abeautifulsite\SimpleImage(getBestImage($width, $height, $person)); if ($img->get_width() / $img->get_height() >= $width / $height) { $img->fit_to_height($height); $centre = round($img->get_width() / 2); $x1 = $centre - $width / 2; $x2 = $centre + $width / 2; $img->crop($x1, 0, $x2, $height); } else { $img->fit_to_width($width); $centre = round($img->get_height() / 2); $y1 = $centre - $height / 2; $y2 = $centre + $height / 2; $img->crop(0, $y1, $width, $y2); } $img = applyFilters($img); $img->output(); }