Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php创建椭圆_Php_Image_Gd_Ellipse - Fatal编程技术网

使用php创建椭圆

使用php创建椭圆,php,image,gd,ellipse,Php,Image,Gd,Ellipse,我需要创建一个椭圆像下面的自定义颜色 我正在使用库来实现这一点 我所做的是: 我为每个部分创建了6个不同的透明图像。 并试图创建一个画布,然后遮罩其上的其他层,但结果不是预期的。 通过这个过程,我只能给图像的第一部分上色 Image::configure(array('driver' => 'gd')); $img = Image::canvas(150,104,'#000')->insert(WWW_ROOT.DS.IMAGES_URL.'test/masks/1

我需要创建一个椭圆像下面的自定义颜色

我正在使用库来实现这一点

我所做的是:
我为每个部分创建了6个不同的透明图像。
并试图创建一个画布,然后遮罩其上的其他层,但结果不是预期的。 通过这个过程,我只能给图像的第一部分上色

    Image::configure(array('driver' => 'gd'));
    $img = Image::canvas(150,104,'#000')->insert(WWW_ROOT.DS.IMAGES_URL.'test/masks/1.png');
    $img->mask(WWW_ROOT.DS.IMAGES_URL.'test/masks/2.png', true);
    $img->mask(WWW_ROOT.DS.IMAGES_URL.'test/masks/3.png', true);
    $img->mask(WWW_ROOT.DS.IMAGES_URL.'test/masks/4.png', true);
    $img->mask(WWW_ROOT.DS.IMAGES_URL.'test/masks/5.png', true);
    $img->mask(WWW_ROOT.DS.IMAGES_URL.'test/masks/6.png', true);
    $img->save(WWW_ROOT.DS.IMAGES_URL.'test/test.png');
    echo $img->response();

我需要帮助来创建上述自定义彩色图像或任何其他选项以实现此目的。

为什么不使用
imageellipse(),
imageFilled()
imageFilled()


不完美但更好:

<?php
     $image = imagecreatetruecolor(300, 300);


    $white    = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
    $gray     = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
    $darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
    $navy     = imagecolorallocate($image, 0x00, 0x00, 0x80);
    $darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);
    $red      = imagecolorallocate($image, 0xFF, 0x00, 0x00);
    $darkred  = imagecolorallocate($image, 0x90, 0x00, 0x00);
    $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);


    for ($i = 60; $i > 50; $i--) {
       imagefilledarc($image, 150, $i, 300, 50, 0, 60, $darknavy, IMG_ARC_PIE);
       imagefilledarc($image, 150, $i, 300, 50, 60, 120 , $darkgray, IMG_ARC_PIE);
       imagefilledarc($image, 150, $i, 300, 50, 120, 180 , $darkred, IMG_ARC_PIE);

       imagefilledarc($image, 150, $i, 300, 50, 180, 240 , $navy, IMG_ARC_PIE);
       imagefilledarc($image, 150, $i, 300, 50, 240, 270 , $gray, IMG_ARC_PIE);
       imagefilledarc($image, 150, $i, 300, 50, 270, 360 , $red, IMG_ARC_PIE);



    }

    imagefilledarc($image, 150, 50, 300, 50, 0, 60, $navy, IMG_ARC_PIE);
    imagefilledarc($image, 150, 50, 300, 50, 60, 120 , $gray, IMG_ARC_PIE);
    imagefilledarc($image, 150, 50, 300, 50, 120, 180 , $red, IMG_ARC_PIE);

    imagefilledarc($image, 150, 50, 300, 50, 180, 240 , $navy, IMG_ARC_PIE);
    imagefilledarc($image, 150, 50, 300, 50, 240, 270 , $gray, IMG_ARC_PIE);
    imagefilledarc($image, 150, 50, 300, 50, 270, 360 , $red, IMG_ARC_PIE);

    imagefilledarc($image, 150, 50, 280, 40, 0, 360, $white, IMG_ARC_PIE);



    header('Content-type: image/png');
    imagepng($image);
    imagedestroy($image);
?>

我终于达到了预期的效果

我所做的是:

使用此函数通过此函数获取每个区域的多边形坐标

在获得每个区域的坐标后,我使用提供的函数创建了所需的图像


感谢大家的帮助,也许这可以帮助其他人。

我已经在php.net上看到过这个例子,但是创建的图像不清晰,我怎么能让它感觉像是有问题的图像呢?我没有最好的解决方案,但也许这能帮上忙:谢谢你的努力,但它与我上面所提供的图像相差甚远。图像仍然失真,不知道如何使其清晰,但我感谢您的努力。
<?php
     $image = imagecreatetruecolor(300, 300);


    $white    = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
    $gray     = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
    $darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
    $navy     = imagecolorallocate($image, 0x00, 0x00, 0x80);
    $darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);
    $red      = imagecolorallocate($image, 0xFF, 0x00, 0x00);
    $darkred  = imagecolorallocate($image, 0x90, 0x00, 0x00);
    $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);


    for ($i = 60; $i > 50; $i--) {
       imagefilledarc($image, 150, $i, 300, 50, 0, 60, $darknavy, IMG_ARC_PIE);
       imagefilledarc($image, 150, $i, 300, 50, 60, 120 , $darkgray, IMG_ARC_PIE);
       imagefilledarc($image, 150, $i, 300, 50, 120, 180 , $darkred, IMG_ARC_PIE);

       imagefilledarc($image, 150, $i, 300, 50, 180, 240 , $navy, IMG_ARC_PIE);
       imagefilledarc($image, 150, $i, 300, 50, 240, 270 , $gray, IMG_ARC_PIE);
       imagefilledarc($image, 150, $i, 300, 50, 270, 360 , $red, IMG_ARC_PIE);



    }

    imagefilledarc($image, 150, 50, 300, 50, 0, 60, $navy, IMG_ARC_PIE);
    imagefilledarc($image, 150, 50, 300, 50, 60, 120 , $gray, IMG_ARC_PIE);
    imagefilledarc($image, 150, 50, 300, 50, 120, 180 , $red, IMG_ARC_PIE);

    imagefilledarc($image, 150, 50, 300, 50, 180, 240 , $navy, IMG_ARC_PIE);
    imagefilledarc($image, 150, 50, 300, 50, 240, 270 , $gray, IMG_ARC_PIE);
    imagefilledarc($image, 150, 50, 300, 50, 270, 360 , $red, IMG_ARC_PIE);

    imagefilledarc($image, 150, 50, 280, 40, 0, 360, $white, IMG_ARC_PIE);



    header('Content-type: image/png');
    imagepng($image);
    imagedestroy($image);
?>