1<?php 2 3require_once 'Image/Canvas.php'; 4 5class Image_3D_Driver_ImageCanvas extends Image_3D_Driver 6{ 7 8 protected $_filetype; 9 protected $_type; 10 11 public function __construct() 12 { 13 parent::__construct(); 14 } 15 16 public function setImageType($type) 17 { 18 $this->_type = (string) $type; 19 } 20 21 public function createImage($x, $y) 22 { 23 $this->_image = Image_Canvas::factory($this->_type, array('width' => $x, 'height' => $y, 'antialias' => 'driver')); 24 } 25 26 protected function _getColor(Image_3D_Color $color) 27 { 28 $values = $color->getValues(); 29 return sprintf('#%02x%02x%02x@%f', (int) ($values[0] * 255), (int) ($values[1] * 255), (int) ($values[2] * 255), 1 - $values[3]); 30 } 31 32 public function setBackground(Image_3D_Color $color) 33 { 34 $this->_image->setFillColor($this->_getColor($color)); 35 $this->_image->rectangle(array('x0' => 0, 'y0' => 0, 'x1' => $this->_image->getWidth(), 'y1' => $this->_image->getHeight())); 36 } 37 38 public function drawPolygon(Image_3D_Polygon $polygon) { 39 40 // Build pointarray 41 $pointArray = array(); 42 $points = $polygon->getPoints(); 43 foreach ($points as $point) { 44 $screenCoordinates = $point->getScreenCoordinates(); 45 $this->_image->addVertex(array('x' => $screenCoordinates[0], 'y' => $screenCoordinates[1])); 46 } 47 $this->_image->setFillColor($this->_getColor($polygon->getColor())); 48 $this->_image->setLineColor(false); 49 $this->_image->polygon(array('connect' => true)); 50 } 51 52 public function drawGradientPolygon(Image_3D_Polygon $polygon) 53 { 54 $this->drawPolygon($polygon); 55 } 56 57 public function save($file) 58 { 59 $this->_image->save(array('filename' => $file)); 60 } 61 62 public function getSupportedShading() { 63 return array(Image_3D_Renderer::SHADE_NO, Image_3D_Renderer::SHADE_FLAT); 64 } 65} 66 67?> 68