如何将多个图像中的单个图像构建为圆形?

时间:2015-06-16 02:17:16

标签: php

我正在努力创造一个幸运型游戏之轮。基本上,它涉及旋转图像,直到它减速并落在奖品上。

问题是我想动态创建滚轮。在某些情况下,我可能只有5个“件”,在其他情况下,我可能有多达10个“件”。所以我需要找到一种方法,使用PHP来构建这样的图像:

enter image description here

几个矩形图像。

  1. 有一种简单的方法吗?
  2. 如果没有,我应该用什么PHP工具来构建它?
  3. 更新

    我现在可以使用切片创建饼图:

    $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
        );
    }
    

    剩下的问题是让图像适合披萨片。所以我需要掩盖那部分的图像。

1 个答案:

答案 0 :(得分:0)

我建议您在GD库上使用Imagemagick Library。因为Imagemagick比GD快。

Imagemagick

这些链接也会对您有所帮助: LayeringMontageFred's Scripts

相关问题