问题描述
我需要使用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.
最后,结果应该是透明的PNG。
Finally, the result should be an alpha-transparent PNG.
PS我的主机上只有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" >
图片结果:
这篇关于PHP等距立方体与GD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!