【问题标题】:How to construct a single image from multiple images as a circle?如何从多个图像中构建单个图像作为一个圆圈?
【发布时间】:2015-06-16 02:17:15
【问题描述】:

我正在尝试创建一个命运之轮类型的游戏。基本上,它涉及旋转图像,直到它放慢速度并落在奖品上。

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

在几个矩形图像中。

  1. 有没有简单的方法可以做到这一点?
  2. 如果不是,我应该使用什么 PHP 工具包来构建它?

更新

我现在可以用切片创建馅饼了:

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

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

【问题讨论】:

标签: php


【解决方案1】:

我建议您通过 GD 库使用 Imagemagick 库。因为 Imagemagick 比 GD 快。

Imagemagick

这些链接也将对您有所帮助: Layering, Montage, Fred's Scripts

【讨论】:

    猜你喜欢
    • 2010-11-06
    • 1970-01-01
    • 2011-06-06
    • 2020-04-09
    • 1970-01-01
    • 2023-03-14
    • 2013-05-05
    • 2015-06-15
    • 1970-01-01
    相关资源
    最近更新 更多