2825 explained code solutions for 75 technologies


php-gdHow to draw filled circle


Check antialiasing strategies to get smooth drawing.

<?php

$im = imagecreatetruecolor(400, 300);

$c_black = imageColorAllocate($im, 0,0,0);
$c_green = imageColorAllocate($im, 46,204,64);

imagefilledellipse($im, 200, 150, 100, 100, $c_green);

imagePng($im, '/tmp/image.png');ctrl + c
imagecreatetruecolor

creates true color GD image object with specified width & height

imageColorAllocate

creates color object to later use in image

imagefilledellipse

creates filled ellipse with specified coordinates, radius and color

200, 150

coordinates of center of circle

100, 100

horizontal and vertical radius should be equal to get circle

$c_green

fill color

imagePng

saves image in PNG format to the given path


How to draw filled circle, php gd

Usage example

<?php

$im = imageCreateTrueColor(400, 300);

$c_black = imageColorAllocate($im, 0,0,0);
$c_green = imageColorAllocate($im, 46,204,64);

imagefilledellipse($im, 200, 150, 100, 100, $c_green);

imagePng($im, '/tmp/image.png');