![](/img/trans.png)
[英]Using PHP's GD functions, how can I create an ellipse that is anti-alised and has a transparent background (PNG24 with alpha)?
[英]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);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.