Crear una imagen con un gráfico de pastel con PHP
PHP
Publicado el 4 de Marzo del 2021 por Kata (76 códigos)
2.273 visualizaciones desde el 4 de Marzo del 2021
Código que genera una imagen png con un gráfico de pastel.


<?php
$myImage = ImageCreate(300, 300);
$white = ImageColorAllocate($myImage, 255, 255, 255);
$red = ImageColorAllocate($myImage, 255, 0, 0);
$green = ImageColorAllocate($myImage, 0, 255, 0);
$blue = ImageColorAllocate($myImage, 0, 0, 255);
$yellow = ImageColorAllocate($myImage, 255, 255, 0);
$lt_red = ImageColorAllocate($myImage, 255, 150, 150);
$lt_green = ImageColorAllocate($myImage, 150, 255, 150);
$lt_blue = ImageColorAllocate($myImage, 150, 150, 255);
$lt_yellow = ImageColorAllocate($myImage, 150, 150, 0);
// dibujamos al parte inferior de la grafica de pastel
for ($i = 170;$i > 150;$i--) {
ImageFilledArc($myImage, 150, $i, 200, 150, 0, 45, $lt_red, IMG_ARC_PIE);
ImageFilledArc($myImage, 150, $i, 200, 150, 45, 90, $lt_yellow, IMG_ARC_PIE);
ImageFilledArc($myImage, 150, $i, 200, 150, 90, 195, $lt_green, IMG_ARC_PIE);
ImageFilledArc($myImage, 150, $i, 200, 150, 195, 360, $lt_blue, IMG_ARC_PIE);
}
ImageFilledArc($myImage, 150, 150, 200, 150, 0, 45, $red, IMG_ARC_PIE);
ImageFilledArc($myImage, 150, 150, 200, 150, 45, 90, $yellow, IMG_ARC_PIE);
ImageFilledArc($myImage, 150, 150, 200, 150, 90, 195, $green, IMG_ARC_PIE);
ImageFilledArc($myImage, 150, 150, 200, 150, 195, 360, $blue, IMG_ARC_PIE);
header("Content-type: image/png");
ImagePNG($myImage);
ImageDestroy($myImage);
?>
Comentarios sobre la versión: 1 (0)
No hay comentarios