Rubblewebs

THESE CODES ARE PROVIDED FOR AN EXAMPLE OF HOW TO USE IMAGEMAGICK WITH PHP. CARE SHOULD BE TAKEN WHEN ACCEPTING USER INPUT.

I TAKE NO RESPONSABILTY FOR ANY PROBLEMS THAT MAY OCCURE WHEN USING ANY OF THIS CODE.

IT IS UP TO YOU TO SECURE THE CODE AND VALIDATE USER INPUT.

Circles

GD example

Circles example
 // Create the canvas
$image = imagecreate(400,400);

// Background colour
$white = ImageColorAllocate($image,255,255,255);

// The colours for the circles
$blue = ImageColorAllocate($image,0, 191, 255 );
$orange = ImageColorAllocate($image,255, 165, 0 );
$red = ImageColorAllocate($image,255,0,0);
$pink = ImageColorAllocate($image,255, 20, 147);
$green = ImageColorAllocate($image,127, 255, 0 );
$purple = ImageColorAllocate($image,148, 0, 211 );
$yellow = ImageColorAllocate($image,238, 221, 130);
$cyan = ImageColorAllocate($image,0, 255, 255);
$dark_green = ImageColorAllocate($image,0, 100, 0  );
$maroon = ImageColorAllocate($image,205, 92, 92 );
$peach = ImageColorAllocate($image,255, 218, 185);

// The array to sellect the colours from
$color = array( $blue, $red, $orange, $pink, $green, $purple, $yellow, $cyan, $dark_green, $maroon, $peach );
$random_colour = array_rand($color,7);

// Creat a bounding rectangle
ImageFilledRectangle($image,0,0,200,200,$white);

// Create the random size circles with random colours but contain them in the bounding box
$x = rand(45, 255);
$y = rand(45, 255);
$r = rand(20, 90);
imagefilledellipse($image, $x, $y, $r,$r, $random_colour[0]);
$x = rand(20, 280);
$y = rand(20, 280);
$r = rand(20, 40);
imagefilledellipse($image, $x, $y, $r,$r, $random_colour[1]);
$x = rand(35, 265);
$y = rand(35, 265);
$r = rand(20, 70);
imagefilledellipse($image, $x, $y, $r,$r, $random_colour[2]);
$x = rand(15, 285);
$y = rand(15, 285);
$r = rand(20, 30);
imagefilledellipse($image, $x, $y, $r,$r, $random_colour[3]);
$x = rand(45, 255);
$y = rand(45, 255);
$r = rand(20, 90);
imagefilledellipse($image, $x, $y, $r,$r, $random_colour[4]);
$x = rand(20, 280);
$y = rand(20, 280);
$r = rand(20, 40);
imagefilledellipse($image, $x, $y, $r,$r, $random_colour[5]);
$x = rand(35, 265);
$y = rand(35, 265);
$r = rand(20, 70);
imagefilledellipse($image, $x, $y, $r,$r, $random_colour[6]);
$x = rand(15, 285);
$y = rand(15, 285);
$r = rand(20, 30);
imagefilledellipse($image, $x, $y, $r,$r, $random_colour[7]);

// Change the background colour to transparent
ImageColorTransparent($image,$white);

// Save the result as circles.png
imagePNG($image,'circles.png');
imagedestroy($image);

This is created using GD rather than ImageMagick; it was some code I was trying out to see what the effect would be. It could be improved on with more randoms for the colour selection etc. For some reason I get some white circles as well and I do not know where they are comming from !


Back