Pear provides image_3d package to create 3D images. Images or light are located in 3D space in x, y, and z coordinates. The generated image is displayed in 2D space and can be stored as PNG, SVG, or output to shell. Image_3d allows you to easily generate some simple 3D objects, suchCubeBody, cone, sphere, text, and pie chart. I checked the pear document and found no examples of image_3d ~ Region ~, I had to study it myself and share my experience with you. Please make a lot of bricks. To put it bluntly, image_3d requires pear and Gd (configure PHP. INI) support.
1. Install image_3d
Download image_3d package. The latest version is 0.4.1.Alpha
Download: http://pear.php.net/package/Image_3D/download
Put the compressed package in a directory with pear. bat, for example, C: \ PHP. If it is wamp5, It is c: \ Wamp \ PHP.
Run the pear install Image_3D-0.4.1.gz to install package:
After the installation is complete, image_3d will be in the C: \ Wamp \ PHP \ pear \ image directory.
2. 3D Coordinate System
For the coordinate system and rotation of image_3d, see for scaling, rotating, or moving objects:
3. Draw a cone
CodeAs follows:
<? PHP // Call the 3D graphics class Require_once ( 'Image/3D. php' ) ; // Create a 3D space $ Image = New Image_3d () ; $ Image -> Setcolor ( New Image_3d_color( 255 , 255 , 255 )) ; // Create a red spot in the lower left corner of the coordinate system $ Light1 = $ Image -> Createlight ( "Light" , Array (- 100 , 100 ,- 100 )) ; $ Light1 -> Setcolor ( New Image_3d_color ( 255 , 0 , 0 )) ; // Create a green spot in the upper-right corner of the coordinate system $ Light2 = $ Image -> Createlight ( "Light" , Array ( 100 ,- 200 ,- 50 )) ; $ Light2 -> Setcolor ( New Image_3d_color ( 0 , 200 , 0 )) ; // Create a 3D cone $ Cone = $ Image -> Createobject ( 'Cone' , Array ( 'Detail' => 360 )) ; $ Cone -> Setcolor ( New Image_3d_color ( 255 , 255 , 255 )) ; // Scale by X, Y, and Z axes $ Cone -> Transform ( $ Image -> Creatematrix ( 'Scale' , Array ( 80 , 150 , 80 ))) ; // Rotate by X, Y, and Z axes $ Cone -> Transform( $ Image -> Creatematrix ( 'Rotation' , Array ( 15 , 0 , 20 ))) ; // Move by X, Y, and Z axis $ Cone -> Transform ( $ Image -> Creatematrix ( 'Move' , Array ( 0 ,- 50 , 0 ))) ; // Create a 2D output image // rendering effect. image_3d provides the following effects: isometric, perspectively, raytrace // reference... \ pear \ image \ 3D \ Renderer directory. $ Image -> Createrenderer( 'Perspectively' ) ; // Image-driven, SVG, ASCII, etc. // see the .. \ pear \ image \ 3D \ driver directory. $ Image -> Createdriver ( 'Gd' ) ; // Create the name and size of the output image $ Image -> Render ( 400 , 300 , 'Object.png' ) ; // Display Echo '' ; ?>
:
4. 3D text effects
Replace the code for creating a 3D cone in the preceding example:
// Create a 3D font $ Text = $ Image -> Createobject ( 'Text' , 'Cnblogs' ) ; $ Text -> Setcolor ( New Image_3d_color ( 255 , 255 , 255 )) ; $ Text -> Transform ( $ Image -> Creatematrix ( 'Scale' , Array ( 10 , 10 , 20 ))) ; $ Text -> Transform ( $ Image -> Creatematrix( 'Rotation' , Array ( 20 , 0 , 20 ))) ; $ Text -> Transform ( $ Image -> Creatematrix ( 'Move' , Array (- 150 ,- 100 , 0 ))) ;
:
Source codeDownload: