簡體   English   中英

使用php創建橢圓

[英]Create ellipse using php

我需要使用自定義顏色創建如下所示的橢圓。

自訂圖片

我正在使用干預圖像庫來實現這一目標。

我所做的是:
我為每個部分創建了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();

我需要幫助來創建上面的“自定義顏色”圖像或任何其他選項來實現此目的。

不完美,但更好:

<?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);
?>

為什么不使用imageellipse(), imagefilledellipse()imagefilledarc()

<?php

    // Création de l'image
    $image = imagecreatetruecolor(100, 100);

    // Allocation de quelques couleurs
    $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);

    // Création de l'effet 3D
    for ($i = 60; $i > 50; $i--) {
       imagefilledarc($image, 50, $i, 100, 50, 0, 45, $darknavy, IMG_ARC_PIE);
       imagefilledarc($image, 50, $i, 100, 50, 45, 75 , $darkgray, IMG_ARC_PIE);
       imagefilledarc($image, 50, $i, 100, 50, 75, 360 , $darkred, IMG_ARC_PIE);
    }

    imagefilledarc($image, 50, 50, 100, 50, 0, 45, $navy, IMG_ARC_PIE);
    imagefilledarc($image, 50, 50, 100, 50, 45, 75 , $gray, IMG_ARC_PIE);
    imagefilledarc($image, 50, 50, 100, 50, 75, 360 , $red, IMG_ARC_PIE);


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

最終,我能夠達到預期的效果。

我所做的是:

使用此圖像通過此jQuery庫獲取每個區域的多邊形坐標。

獲取每個區域的坐標后,我使用Intervention Image Library提供的多邊形函數創建了所需的圖像。

感謝大家的幫助,也許這可以幫助其他人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM