【问题标题】:vertically justify the created pattern垂直对齐创建的图案
【发布时间】: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


    【解决方案1】:

    根据图像高度和圆数计算偏移量。顺便说一句,你应该调整你的计数计算:

    $vrtcl_c = ceil($ch / $c_diamtr);
    $verticalOffset = ($ch - $vrtcl_c * c_diamtr) / 2;
    

    然后,移动你的图纸:

    for ($j = 0; $j < $vrtcl_c; $j++){ //loop vertical
        $draw->ellipse( $c_radius + $c_diamtr * $i, 
                        $c_radius + $c_diamtr * $j + $verticalOffset,
                        $c_radius, $c_radius, 0, 360 );
    }
    

    【讨论】:

    • 太棒了。是的,我有计划向上或向下计数。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2010-12-03
    • 2022-12-23
    • 1970-01-01
    • 1970-01-01
    • 2013-06-26
    • 2016-09-06
    相关资源
    最近更新 更多