PHP - To create graphical image with simple code

by Subramanian 2013-03-15 17:04:32

PHP - To create graphical image with simple code

The following code is used to create a graphical design like a below image.



<?php
$pic = imagecreatetruecolor(400,400); // for create canvas with 400 * 400 size

$bluecol = 0;

for ($i = -10; $i < 410; $i += 80) {
for ($j = -10; $j < 410; $j += 80) {
$brush = imagecreate(100,100); // for create brush (lines thickness)

$brushtrans = imagecolorallocate($brush, 0, 0, 0); //forallocate color for brush
imagecolortransparent($brush, $brushtrans);

for ($k = 1; $k < 18; ++$k) {
$color = imagecolorallocate($brush, 255, $k * 15, $bluecol);// allocate different color for line's color
imagefilledellipse($brush, $k * 2, $k * 2, 1, 1, $color); //for draw ellips (border only)
}

imagesetbrush($pic, $brush);
imageellipse($pic, $i, $j, 50, 50, IMG_COLOR_BRUSHED);

imagedestroy($brush); // free the brush memory
}

$bluecol += 40;
}

imagepng($pic,"subhu.png",9);// create png image(here u van set the path for image and 9 indicate resolution for image)
imagedestroy($pic); // free the memory
?>
<img src='subhu.png'/>



Output:
The output is generated with png image.

s.png
982
like
0
dislike
0
mail
flag

You must LOGIN to add comments