Reputation: 254
$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
when I set font size to 18, everything is ok, other font size will cause apache "dead", seems 18 is the only luck number, very strange, is it ?
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 ?
Upvotes: 1
Views: 196
Reputation: 254
It seems there something wrong with the font file, change to another common font, everything is ok now.
Upvotes: 1