Paint 3-D images with PHP
April 27, 2008PHP, a language originally intended for Web development, has been used for years to manage dynamic Web sites and database applications. Extensions to the language available through the PHP Extension and Application Repository (PEAR) have allowed developers to take the language in new and interesting directions. PEAR’s Image_3D package is an object-oriented interface for creating three-dimensional (3-D) graphics in a variety of formats, including PNG and SVG, two image formats with increasing support by modern Web browsers. Find out how to use the Image_3D package, learn the limitations of using dynamic 3-D images, and investigate solutions and practical applications of 3-D graphics.
In this tutorial
This tutorial is for PHP programmers interested in dynamically generating 3-D graphics. Images can be created from scratch, built up from objects and light sources positioned in space according to X, Y, and Z coordinates. Programmers with experience using 3-D Studio Max will see how to import objects from 3DS files into PHP creations. Complex surfaces defined by parametric equations can easily be mapped using Image_3D. Finally, business applications and data reports can be enhanced by adding pie charts generated on the fly.
Prerequisites
This tutorial assumes at least a base knowledge of objects and classes, as the entire interface for Image_3D is object-oriented. Access to a Linux® shell account or a Windows® command prompt is required for executing command-line PHP examples shown in the first half of the tutorial. Basic experience with JavaScript is also assumed.
System requirements
The following software and tools are required to follow along:
PHP V5 The Image_3D package is written using the PHP V5 object and class syntax. Image_3D The PEAR package will need to be installed. Typically, the installation of Image_3D should be easy if you have root (or administrator) access to your machine. Because Image_3D is in alpha release, the PEAR installation may complain that the package is not "stable." Use the -f option to force the installation:
GD Examples in the second half of the tutorial can be built for use on a Web site. The and are two options, if you don’t already have a Web server available.SVG viewerMozilla Firefox V1.5Adobe SVG plug-in