【发布时间】:2015-10-19 05:38:41
【问题描述】:
我已经使用 PHP-Imagick 创建了重复圆圈的图案图像,就像上面给出的示例图像一样。下面是创建上面图像的代码。我已经明确地注释了代码,并且变量名称保持非常详细,以便了解发生了什么。
$canvas = new Imagick();
$cw = 700; // user provided width
$ch = 300; //user provided height
$hrzntl_c = 10; //user provided - number of horizontal circles - min 2 and max 200
$c_diamtr = $cw / $hrzntl_c; //set the diameter of circle
$c_radius = $c_diamtr /2; //set the radius of circle
$vrtcl_c = $ch / $c_diamtr; //calculated number of vertical circles.
$canvas->newImage( $cw, $ch, new ImagickPixel( "seagreen" ) ); //create a canvas
$draw = new ImagickDraw(); // create a draw object
$draw->setFillColor( new ImagickPixel( "white" ) ); // set the fill color
for ($i = 0; $i <= $hrzntl_c; $i++){ //loop horizontal
for ($j = 0; $j <= $vrtcl_c; $j++){ //loop vertical
$draw->ellipse( $c_radius + $c_diamtr * $i, $c_radius + $c_diamtr * $j, $c_radius, $c_radius, 0, 360 );
}
}
$canvas->drawImage( $draw ); // render the circles to the canvas
$canvas->setImageFormat( "png" ); // set the image format to png
header("Content-Type: image/png"); // Output the image
echo $canvas;
问题:现在您已经知道圆圈被设计为水平对齐。我也需要帮助来证明垂直圆圈的合理性。查看示例图像的底部,您可以看到圆圈确实不合理。通过“合理”,我的意思是如果您看到顶部有一个半圆/全圆,那么您也应该在底部看到半圆/全圆。喜欢这个完美的例子。
【问题讨论】:
标签: php image math image-processing imagick