PHP SLIM : How to return dynamically generated images -
i trying display dynamically generated image slim controller getting blank screen. thanks.
public function texttoimage($request, $response, $args) { // text draw $text = "hello world"; $length=strlen($text); // create image $im = imagecreatetruecolor($length*12, 30); // create colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 44, 62, 80); $boxcolor=imagecolorallocate($im, 95, 128, 149); $font = 'helvetica.ttf'; imagefilledrectangle($im, 0, 0, $length*9+$capitaladjust, 29, $white); imagettftext($im, 13, 0, 0, 20, $black, $font, $text); $response->getbody()->write(base64_encode($im)); $response = $response->withheader('content-type', 'image/png'); return $response; }
base64 encoding $im
not create valid png file. try using imgpng , sending raw contents of png file creates.
the code this:
ob_start(); imagepng($im); $data = ob_get_contents(); ob_end_clean(); $response->getbody()->write($data); $response = $response->withheader('content-type', 'image/png'); return $response;
Comments
Post a Comment