static function verifycode_imagick($img_width = 80, $img_height = 30, $addRandomLines = true, $swirl = true)
{
$fontSize = 24;
/* imagick对象 */
$Imagick = new \Imagick();
/* 背景对象 */
$bg = new \ImagickPixel();
/* Set the pixel color to white */
$bg->setColor('rgb(235,235,235)');
/* 画刷 */
$ImagickDraw = new \ImagickDraw();
if (is_file(self::$verifyCodeFontFile)) {
$ImagickDraw->setFont(self::$verifyCodeFontFile);
}
$ImagickDraw->setFontSize($fontSize);
$ImagickDraw->setFillColor('black');
$code = strtoupper(RandomKey::string(self::$verifyCodeLength));
/* Create new empty image */
$Imagick->newImage($img_width, $img_height, $bg);
/* Write the text on the image */
$Imagick->annotateImage($ImagickDraw, 4, 20, 0, $code);
/* 变形 */
if ($swirl) {
$Imagick->swirlImage(10);
}
/* 随即线条 */
if ($addRandomLines) {
$ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30));
$ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30));
$ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30));
$ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30));
$ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30));
}
/* Draw the ImagickDraw object contents to the image. */
$Imagick->drawImage($ImagickDraw);
/* Give the image a format */
$Imagick->setImageFormat('png');
/* Send headers and output the image */
return array('image' => $Imagick->getImageBlob(), 'code' => $code);
}