带有 GD 的 PHP 等距立方体 [英] PHP Isometric cube with GD

查看:22
本文介绍了带有 GD 的 PHP 等距立方体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用 PHP 和 GD 创建类似的东西:

I need to create something like this with PHP and GD:

三个可见的人脸将是同一张图片的三个部分,我知道其中的坐标.

The three visible faces will be three parts of the same image, of which I know the coordinates.

我想这可以通过图像转换和一些数学来完成.

I suppose that this can be done with image transformations and some maths.

立方体的旋转将始终相同.

The rotation of the cube will be always the same.

我不需要像图片中那样的描边"边缘和面部照明,我只需要一个无阴影"立方体.

I don't need "stroke" edges and face lighting like in that picture, I just need a "shadeless" cube.

最后,结果应该是一个 alpha 透明的 PNG.

Finally, the result should be an alpha-transparent PNG.

附言我的主机上只有 GD,我无法访问 ImageMagick.

P.S. I only have GD on my host, I don't have access to ImageMagick.

推荐答案

您正在寻找类似的东西吗?

you are searching for something like this?

<?php
$size=100;

$first_poligon = array(
            0,  $size/4,  // Point 1 (x, y) ---->  0,20
            $size/2,  $size/2, // Point 2 (x, y) ---->  50,50
            $size/2,  $size,    // Point 3 (x, y) ---->  50,100
            0, ($size/4)*3,  // Point 4 (x, y) ---->  0,60
            );
$second_poligon = array(
            0,  $size/4,  // Point 1 (x, y) ---->  0,33
            $size/2,  0, // Point 2 (x, y) ---->  50,0
            $size,  $size/4,    // Point 3 (x, y) ---->  100,20
            $size/2,  $size/2,  // Point 4 (x, y) ---->  50,50
            );          
$third_poligon = array(
            $size,  $size/4,  // Point 1 (x, y) ---->  100,20
            $size/2,  $size/2, // Point 2 (x, y) ---->  50,50
            $size/2,  $size,    // Point 3 (x, y) ---->  50,100
            $size, ($size/4)*3,  // Point 4 (x, y) ---->  100,60
            );          

$im = imagecreatetruecolor($size, $size);

$fondo   = imagecolorallocate($im, 51, 0, 0);
imagefilledrectangle($im, 0, 0, $size, $size, $fondo);

$blue = imagecolorallocate($im, 0, 0, 255);
$white = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);

imagefilledpolygon($im, $first_poligon, 4, $blue);
imagefilledpolygon($im, $second_poligon, 4, $white);
imagefilledpolygon($im, $third_poligon, 4, $red);

imagepng($im, './image.png');

imagedestroy($im);
?>
 <img src="image.png" > 

图像结果:

这篇关于带有 GD 的 PHP 等距立方体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆