Exemple #1
0
 protected function _getStop(Image_3D_Color $color, $offset = 0, $alpha = null)
 {
     $values = $color->getValues();
     $values[0] = (int) round($values[0] * 255);
     $values[1] = (int) round($values[1] * 255);
     $values[2] = (int) round($values[2] * 255);
     if ($alpha === null) {
         $values[3] = 1 - $values[3];
     } else {
         $values[3] = 1 - $alpha;
     }
     return sprintf("\t\t\t<stop id=\"stop%d\" offset=\"%.1f\" style=\"stop-color: rgb(%d, %d, %d); stop-opacity: %.4f;\" />\n", $this->_id++, $offset, $values[0], $values[1], $values[2], $values[3]);
 }
Exemple #2
0
 protected function _getColor(Image_3D_Color $color)
 {
     $values = $color->getValues();
     $values[0] = (int) round($values[0] * 255);
     $values[1] = (int) round($values[1] * 255);
     $values[2] = (int) round($values[2] * 255);
     $values[3] = (int) round($values[3] * 127);
     $color = '';
     if ($values[3] > 0) {
         $color = 'rgba(' . implode(',', $values) . ')';
     } else {
         unset($values[3]);
         $color = 'rgb(' . implode(',', $values) . ')';
     }
     return $color;
 }
Exemple #3
0
 protected function _getColor(Image_3D_Color $color, $alpha = 1.0)
 {
     $values = $color->getValues();
     $values[0] = (int) round($values[0] * 255);
     $values[1] = (int) round($values[1] * 255);
     $values[2] = (int) round($values[2] * 255);
     $values[3] = (int) round((1 - (1 - $values[3]) * $alpha) * 127);
     if ($values[3] > 0) {
         // Tranzparente Farbe allokieren
         $color = imageColorExactAlpha($this->_image, $values[0], $values[1], $values[2], $values[3]);
         if ($color === -1) {
             // Wenn nicht Farbe neu alloziieren
             $color = imageColorAllocateAlpha($this->_image, $values[0], $values[1], $values[2], $values[3]);
         }
     } else {
         // Deckende Farbe allozieren
         $color = imageColorExact($this->_image, $values[0], $values[1], $values[2]);
         if ($color === -1) {
             // Wenn nicht Farbe neu alloziieren
             $color = imageColorAllocate($this->_image, $values[0], $values[1], $values[2]);
         }
     }
     return $color;
 }
Exemple #4
0
 protected function _getColor(Image_3D_Color $color, $alpha = 1.0)
 {
     $values = $color->getValues();
     return array($values[0], $values[1], $values[2], (1 - $values[3]) * $alpha);
 }
Exemple #5
0
 /**
  * Render the image
  *
  * Render the image into the metioned file
  *
  * @param string $file Filename
  *
  * @return  void
  */
 public function render($file)
 {
     // Render image...
     $canvas = $this->_raytrace();
     // Write canvas to file
     $this->_image = imagecreatetruecolor($this->_size[0] * 2, $this->_size[1] * 2);
     $bg = $this->_getColor($this->_background);
     imagefill($this->_image, 1, 1, $bg);
     $x = 0;
     foreach ($canvas as $row) {
         $y = 0;
         foreach ($row as $pixel) {
             if (count($pixel)) {
                 $color = new Image_3D_Color();
                 $color->merge($pixel);
                 imagesetpixel($this->_image, $x, $y, $this->_getColor($color));
             }
             ++$y;
         }
         ++$x;
     }
     imagepng($this->_image, $file);
 }
Exemple #6
0
 protected function _getColor(Image_3D_Color $color)
 {
     $values = $color->getValues();
     return sprintf('#%02x%02x%02x@%f', (int) ($values[0] * 255), (int) ($values[1] * 255), (int) ($values[2] * 255), 1 - $values[3]);
 }
 /**
  * Create an appropriate array representation from a Image_3D_Color object
  * 
  * @param Image_3D_Color $color Color to transform to rgba syntax
  * @param float          $alpha optional Override the alpha value set in the Image_3D_Color object
  * 
  * @return array Array of color values reflecting the different color
  *               components of the input object
  */
 protected function _getRgba(Image_3D_Color $color, $alpha = null)
 {
     $values = $color->getValues();
     $values[0] = (int) round($values[0] * 255);
     $values[1] = (int) round($values[1] * 255);
     $values[2] = (int) round($values[2] * 255);
     if ($alpha !== null) {
         $values[3] = 1.0 - $alpha;
     } else {
         $values[3] = 1.0 - $values[3];
     }
     return array('r' => $values[0], 'g' => $values[1], 'b' => $values[2], 'a' => $values[3]);
 }