9951 explained code solutions for 126 technologies


php-gdHow to draw 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);

imageellipse($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

imageellipse

creates ellipse with specified coordinates, radius and border 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 circle, php gd

Usage example

<?php

$im = imagecreatetruecolor(400, 300);

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

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

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