0

I am trying to create a wheel of fortune type game. Basically, it involves spinning an image like until it slows down and lands on a prize.

The problem is that I want to dynamically create the wheel. In some cases I might have only 5 "pieces" and in other cases I might have as many as 10 "pieces". So I need to find a way, using PHP, to build an image like this:

enter image description here

Out of several rectangular images.

  1. Is there an easy way to do this?
  2. If not, what PHP kit should I use to build this?

UPDATE

I am now able to create the pie with the slices:

$saveImage = 'image.png';
if (file_exists($saveImage)) {
    unlink($saveImage);
}

$height = $width  = 400;

// 1. Create a blank canvas image with transparent circle
$image = imagecreatetruecolor($width, $height);

$bg          = imagecolorallocate($image, 0, 0, 0);
$col_ellipse = imagecolorallocate($image, 255, 255, 255);

imagecolortransparent($image, $bg);

imagefilledellipse($image, ($width / 2), ($height / 2), $width, $height, $col_ellipse);

// 3. Divide image into slices
$numberOfSlices = sizeof($images);
$black = imagecolorallocate($image, 0, 0, 0);
$sliceDegrees = 360 / $numberOfSlices;
$first = true;
$radius = 0.5 * $width;

// start point is always the middle
$startX = $width / 2;
$startY = $height / 2;

$points = array();

for ($i = 0 ; $i < $numberOfSlices; $i++)
{
    $angle = $i * ($sliceDegrees);
    $endX = $radius * cos(deg2rad($angle)) + $radius;
    $endY = $radius * sin(deg2rad($angle)) + $radius;

    $points[] = array (
    $endX, $endY
    );

    imageline(
    $image, 
    $startX, $startY, 
    $endX ,  $endY, 
    //150, 150 + ($i * 10), 
    $black
    );
}

The remaining problem is getting the image to fit in on the pizza slice. So I need to mask the image over that portion.

rockstardev
  • 13,479
  • 39
  • 164
  • 296
  • 3
    You can use the [GD Library](http://php.net/manual/en/book.image.php) to create the image – CrayonViolent Jun 16 '15 at 02:21
  • 1
    Have a look at [this](http://stackoverflow.com/questions/7203160/php-gd-use-one-image-to-mask-another-image-including-transparency) :) – someOne Jun 16 '15 at 04:29

1 Answers1

0

I would suggest you to use Imagemagick Library for this over GD Library. As Imagemagick is faster than GD.

Imagemagick

Also these links will be helpful to you : Layering, Montage, Fred's Scripts

Harsh Makani
  • 761
  • 5
  • 11