$image = new \Imagick(); $draw = new \ImagickDraw(); $fillColor = new \ImagickPixel('black'); $bgColor = new \ImagickPixel('gray'); $fontSize = 24; $text = 'helloworld'; $text = substr($text, 0, rand(1, 10)); $font = '/home/koogua/font/yy.ttf'; $draw->setFont($font); $draw->setFontSize($fontSize); $draw->setFillColor($fillColor); $draw->setStrokeAntialias(true); $draw->setTextAntialias(true); $draw->setgravity(\Imagick::GRAVITY_CENTER); $draw->annotation(0, 0, $text); $metrics = $image->queryFontMetrics($draw, $text); $image->newImage($metrics['textWidth'] + 30, $metrics['textHeight'] + 10, $bgColor); $image->setImageFormat('png'); $image->drawImage($draw); $draw->destroy(); // $image->writeImage('test.png'); header('Content-Type: image/png'); echo $image->getImageBlob(); exit; // $this->response->setContentType( 'image/png'); // $this->response->setContent($image->getImageBlob()); // $this->response->send();
enviroment: phalcon
output with font : refresh the page 1- 5 times, capcha image is ok, after 5 times, apache "dead"
output without font : ok
save file : ok
enviroment: another php framework (rewrite is enabled)
output with font : ok
output without font : ok
save file: ok
enviroment: pure php
output with font : ok
output without font : ok
save file: ok
can someone test the above code ?
stackoverflow discussion link: https://stackoverflow.com/questions/32556611/output-captcha-image-with-font-cause-apache-dead