Exemplo n.º 1
0
 function draw(Canvas $dest, $x = null, $y = null, $width = null, $height = null)
 {
     $image = new Canvas($width, $height);
     $p = $image->getPainter();
     if (!$x) {
         $x = 0;
     }
     if (!$y) {
         $y = 0;
     }
     if (!$width) {
         $width = $dest->width;
     }
     if (!$height) {
         $height = $dest->height;
     }
     if ($width && $height) {
         $grad = $height;
         // Top down
         $this->colors['step'] = array((double) ($this->colors['delta'][0] / $grad), (double) ($this->colors['delta'][1] / $grad), (double) ($this->colors['delta'][2] / $grad));
         $w = $width;
         for ($n = 0; $n < $grad; $n++) {
             $c = new RgbColor(floor($this->colors['first'][0] + $this->colors['step'][0] * $n), floor($this->colors['first'][1] + $this->colors['step'][1] * $n), floor($this->colors['first'][2] + $this->colors['step'][2] * $n));
             // Console::debug("Row %d: rgb(%d,%d,%d)", $n, $c->r, $c->g, $c->b);
             $p->drawLine(0, $n, $w, $n, $c);
         }
         imagecopy($dest->getImage(), $image->getImage(), $x, $y, 0, 0, $width, $height);
     } else {
         throw new BadArgumentException();
     }
 }
Exemplo n.º 2
0
 function applyFilter(Canvas $canvas)
 {
     $himage = $canvas->getImage();
     if (function_exists('imagefilter')) {
         // If gd is bundled this will work
         imagefilter($himage, IMG_FILTER_GRAYSCALE);
     } else {
         // If not we need to do some enumeration
         $total = imagecolorstotal($himage);
         if ($total > 0) {
             // This works for indexed images but not for truecolor
             for ($i = 0; $i < $total; $i++) {
                 $index = imagecolorsforindex($himage, $i);
                 $avg = ($index["red"] + $index["green"] + $index["blue"]) / 3;
                 $red = $avg;
                 $green = $avg;
                 $blue = $avg;
                 imagecolorset($himage, $i, $red, $green, $blue);
             }
         } else {
             // For truecolor we need to enum it all
             for ($x = 0; $x < imagesx($himage); $x++) {
                 for ($y = 0; $y < imagesy($himage); $y++) {
                     $index = imagecolorat($himage, $x, $y);
                     $avg = (($index & 0xff) + ($index >> 8 & 0xff) + ($index >> 16 & 0xff)) / 3;
                     imagesetpixel($himage, $x, $y, $avg | $avg << 8 | $avg << 16);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 function applyFilter(Canvas $canvas)
 {
     $himage = $canvas->getImage();
     // If not we need to do some enumeration
     $total = imagecolorstotal($himage);
     if ($total > 0) {
         // This works for indexed images but not for truecolor
         for ($i = 0; $i < $total; $i++) {
             $index = imagecolorsforindex($himage, $i);
             $rgb = rgb($index['red'], $index['green'], $index['blue']);
             $hsv = hsv($rgb);
             $hsv->hue = $this->hue;
             $rgb = rgb($hsv);
             $red = $rgb->red;
             $green = $rgb->green;
             $blue = $rgb->blue;
             imagecolorset($himage, $i, $red, $green, $blue);
         }
     } else {
         // For truecolor we need to enum it all
         for ($x = 0; $x < imagesx($himage); $x++) {
             for ($y = 0; $y < imagesy($himage); $y++) {
                 $index = imagecolorat($himage, $x, $y);
                 $rgb = rgb($index['red'], $index['green'], $index['blue'], $index['alpha']);
                 $hsv = hsv($rgb);
                 $hsv->hue = $this->hue;
                 $rgb = rgb($hsv);
                 $red = $rgb->red;
                 $green = $rgb->green;
                 $blue = $rgb->blue;
                 imagesetpixel($himage, $x, $y, $red << 16 | $green < 8 | $blue);
             }
         }
     }
 }
Exemplo n.º 4
0
 function applyFilter(Canvas $canvas)
 {
     $himage = $canvas->getImage();
     $m = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0));
     $div = 16;
     $offs = 0;
     ImageUtils::imageconvolution($himage, $m, $div, $offs);
 }
Exemplo n.º 5
0
 function applyFilter(Canvas $canvas)
 {
     $himage = $canvas->getImage();
     if (function_exists('imagefilter') && defined('IMG_FILTER_COLORIZE')) {
         // If gd is bundled this will work
         imagefilter($himage, IMG_FILTER_COLORIZE, $this->r, $this->g, $this->b);
     } else {
         throw new FunctionNotSupportedException("Colorize not supported by this version of GD");
     }
 }
Exemplo n.º 6
0
 function applyFilter(Canvas $canvas)
 {
     $himage = $canvas->getImage();
     if ($this->usegdfilter) {
         if (!imagefilter($himage, IMG_FILTER_PIXELATE, $this->pixelsize, $this->advanced)) {
             throw new GraphicsException("Failed to apply filter");
         }
     } else {
         // TODO: Implement our own pixelation filter
     }
     $canvas->setImage($himage);
     return null;
 }
Exemplo n.º 7
0
 function draw(Canvas $dest, $x = null, $y = null, $width = null, $height = null)
 {
     $c = new Canvas($width, $height, rgb($this->props['background']));
     $p = $c->getPainter();
     $p->drawRect(0, 0, $width - 1, $height - 1, rgb($this->props['bordercolor']));
     $labels = $this->dataset->getLabels();
     $labelcount = count($labels);
     // $ls = floor($height / $labelcount) - 4;
     $ls = 16;
     for ($i = 0; $i < $labelcount; $i++) {
         $x1 = 3;
         $y1 = 3 + ($ls + 2) * $i;
         $x2 = $x1 + $ls;
         $y2 = $y1 + $ls;
         $p->drawFilledRect($x1, $y1, $x2, $y2, rgb(80, 80, 80), rgb(rand(0, 200), rand(0, 200), rand(0, 200)));
     }
     imagecopy($dest->getImage(), $c->getImage(), $x, $y, 0, 0, $width, $height);
 }
Exemplo n.º 8
0
 function applyFilter(Canvas $canvas)
 {
     $himage = $canvas->getImage();
     $iw = imagesx($himage);
     $ih = imagesy($himage);
     switch ($this->placement) {
         case WatermarkImageFilter::POS_RELATIVE:
             $dx = $this->x >= 0 ? $this->x : $iw - $this->width + $this->x + 1;
             $dy = $this->y >= 0 ? $this->y : $ih - $this->height + $this->y + 1;
             break;
         case WatermarkImageFilter::POS_ABSOLUTE:
             $dx = $this->x;
             $dy = $this->y;
             break;
         case WatermarkImageFilter::POS_CENTERED:
             $dx = $iw / 2 + $this->x;
             $dy = $ih / 2 + $this->y;
             break;
     }
     imagecopymerge_alpha($himage, $this->hwatermark, $dx, $dy, 0, 0, $this->width, $this->height, 0);
 }
Exemplo n.º 9
0
 function applyFilter(Canvas $canvas)
 {
     $himage = $canvas->getImage();
     $rheight = $this->_os->get('reflectionheight', 25);
     $iheight = imagesy($himage);
     $iwidth = imagesx($himage);
     if ($this->_os->get('resizecanvas', false)) {
         // create new canvas of iheight+rheight, set offset to
         // iheight
         $offs = $iheight;
         $hreflect = imagecreatetruecolor($iwidth, $iheight + $rheight);
     } else {
         // create new canvas of iheight, set offset to iheight to
         // iheight-rheight
         $offs = $iheight - $rheight;
         $hreflect = imagecreatetruecolor($iwidth, $iheight);
     }
     if ($this->_os->get('background', null)) {
         // Fill with background if specified, note that this disables
         // the alpha saving
         imagefilledrectangle($hreflect, 0, 0, imagesx($hreflect), imagesy($hreflect), new Color($this->_os->get('background')));
     } else {
         // Disable alphablending and enable saving of the alpha channel
         imagealphablending($hreflect, false);
         imagesavealpha($hreflect, true);
     }
     imagecopy($hreflect, $himage, 0, 0, 0, 0, $iwidth, $iheight);
     $as = 80 / $rheight;
     $sc = $this->_os->get('scale', 2);
     for ($y = 1; $y <= $rheight; $y++) {
         for ($x = 0; $x < $iwidth; $x++) {
             $rgba = imagecolorat($himage, $x, $offs - $y * $sc);
             $alpha = max($rgba >> 24 & 0x7f, 47 + $y * $as);
             $rgba = imagecolorallocatealpha($hreflect, $rgba >> 16 & 0xff, $rgba >> 8 & 0xff, $rgba & 0xff, $alpha);
             imagesetpixel($hreflect, $x, $offs + $y - 1, $rgba);
         }
     }
     return $hreflect;
 }
Exemplo n.º 10
0
 function draw(Canvas $dest, $x = null, $y = null, $width = null, $height = null)
 {
     $hi = $dest->getImage();
     $str = '*' . $this->_text . '*';
     if ($x && $y && $width && $height) {
         // Each character is 12 units wide, so let's figure out how wide
         // we should make the output. We add 2 for the padding.
         $outwidth = strlen($str) * 14;
         $unitwidth = (int) ($width / $outwidth);
         $rx = 0;
         for ($i = 0; $i < strlen($str); $i++) {
             $charbin = $this->getCharacter($str[$i]);
             for ($j = 0; $j < 9; $j++) {
                 $bw = $charbin[$j] == '1' ? 1 : 0;
                 imagefilledrectangle($hi, $x + $rx * $unitwidth, $y, $x + ($rx + $bw + 1) * $unitwidth, $y + $height, $j % 2 ? 0xffffff : 0x0);
                 $rx = $rx + 2 + $bw;
             }
             $rx = $rx + 2;
         }
     } else {
         new BadArgumentException();
     }
 }
Exemplo n.º 11
0
 function drawText(Canvas $canvas, $x, $y, $color, $text)
 {
     $himage = $canvas->getImage();
     if ($this->effect == BitmapFont::EFFECT_OUTLINE) {
         $ow = 1;
         for ($xx = $x - $ow; $xx <= $x + $ow; $xx++) {
             for ($yy = $y - $ow; $yy <= $y + $ow; $yy++) {
                 imagestring($himage, $this->font, $xx, $yy, $text, $this->options->getColor($himage));
             }
         }
     } elseif ($this->effect == BitmapFont::EFFECT_SHADOW) {
         $ow = 1;
         for ($z = 0; $z <= $ow; $z++) {
             imagestring($himage, $this->font, $x + $z, $y + $z, $text, $this->options->getColor($himage));
         }
     } elseif ($this->effect == BitmapFont::EFFECT_BOLD) {
         imagestring($himage, $this->font, $x + 1, $y, $text, $color->getColor($himage));
     }
     imagestring($himage, $this->font, $x, $y, $text, $color->getColor($himage));
 }
Exemplo n.º 12
0
 /**
  * @brief Draw the canvas onto another canvas.
  *
  * @param Canvas $dest The destination canvas
  * @param integer $x The left coordinate of the destination canvas
  * @param integer $y The top coordinate of the destination canvas
  * @param integer $width The width of the drawing
  * @param integer $height The height of the drawing
  */
 function draw(Canvas $dest, $x = null, $y = null, $width = null, $height = null, $alpha = false)
 {
     $this->checkMeta();
     $dstimage = $dest->getImage();
     if (!$x) {
         $x = 0;
     }
     if (!$y) {
         $y = 0;
     }
     if (!$width) {
         $width = $this->width;
     }
     if (!$height) {
         $height = $this->height;
     }
     if (!$alpha) {
         imagecopy($dstimage, $this->himage, $x, $y, 0, 0, $width, $height);
     } else {
         imagecopymerge_alpha($dstimage, $this->himage, $x, $y, 0, 0, $width, $height, 0);
     }
 }
Exemplo n.º 13
0
 function __construct(Canvas $canvas)
 {
     $this->himage = $canvas->getImage();
     $this->canvas = $canvas;
 }
Exemplo n.º 14
0
 function applyFilter(Canvas $canvas)
 {
     $himage = $canvas->getImage();
     ImageUtils::imageconvolution($himage, $this->matrix, $this->div, $this->offset);
 }