当前位置: 首页>>代码示例>>PHP>>正文


PHP Canvas类代码示例

本文整理汇总了PHP中Canvas的典型用法代码示例。如果您正苦于以下问题:PHP Canvas类的具体用法?PHP Canvas怎么用?PHP Canvas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Canvas类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render

 function render(SceneState $ss, ActorState $as, Canvas $c)
 {
     $font = new TrueTypeFont($this->font, $this->size);
     $p = $c->getPainter();
     $p->drawFilledRect(0, 0, $c->width, $c->height, rgb($this->background), rgb($this->background));
     $c->drawText($font, rgb($this->color), 0, 0, $this->text);
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:7,代码来源:text.php

示例2: applyFilter

 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);
             }
         }
     }
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:35,代码来源:hue.php

示例3: applyFilter

 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);
                 }
             }
         }
     }
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:31,代码来源:grayscale.php

示例4: draw

 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();
     }
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:31,代码来源:gradient.php

示例5: applyFilter

 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);
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:8,代码来源:blur.php

示例6: testInsertX

 /**
  * @dataProvider getInsertXData
  */
 public function testInsertX($x, $w, array $expectedData)
 {
     $from = [0 => [0 => 'A', 1 => 'B', 2 => 'C'], 1 => [0 => 'D', 1 => 'E', 2 => 'F']];
     $from = new Canvas(null, $from);
     $to = [0 => [0 => 'X', 1 => 'Y', 2 => 'Z']];
     $to = new Canvas(null, $to);
     $from->insert($to, 0, $x, 0, $w);
     $this->assertEquals($expectedData, $from->getArrayCopy());
 }
开发者ID:mathielen,项目名称:report-write-engine,代码行数:12,代码来源:CanvasTest.php

示例7: applyFilter

 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");
     }
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:10,代码来源:colorize.php

示例8: applyFilter

 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;
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:13,代码来源:pixelize.php

示例9: getMapCanvas

 public function getMapCanvas($width, $height)
 {
     $url = $this->getApiQueryUrl(["w" => $width, "h" => $height]);
     $map = file_get_contents($url);
     $c = Canvas::createFromString($map);
     return $c;
 }
开发者ID:noccy80,项目名称:cherryphp,代码行数:7,代码来源:map.php

示例10: test__clone

 /**
  * @covers Image\Canvas::__clone
  */
 public function test__clone()
 {
     $this->object->createImage(200, 200);
     $clone = clone $this->object;
     $this->assertEquals($this->object->getImageWidth(), $clone->getImageWidth());
     $this->assertEquals($this->object->getImageHeight(), $clone->getImageHeight());
 }
开发者ID:npetrovski,项目名称:php5-image,代码行数:10,代码来源:CanvasTest.php

示例11: generateThumb

 private static function generateThumb($path, $name, $width, $heigth)
 {
     $save = self::$path . DIRECTORY_SEPARATOR . $name;
     $thumb = \Canvas::Instance();
     $thumb->carrega($path);
     $thumb->redimensiona($width, $heigth, 'crop');
     $thumb->grava($save);
 }
开发者ID:fernandopetry,项目名称:pwork,代码行数:8,代码来源:Thumbnail.php

示例12: draw

 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);
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:18,代码来源:legend.php

示例13: applyImageFilter

 public function applyImageFilter(Canvas $canvas, Rect $rect = null)
 {
     if ($rect) {
         $image = $canvas->getImageRect($rect);
     } else {
         $image = $canvas;
     }
     $im = $image->toImagick();
     $im->adaptiveSharpenImage($this->radius, $this->sigma);
     $image->fromImagick($im);
     if ($rect) {
         // Draw dest onto canvas
         $c = new Canvas();
         $c->fromImagick($image);
         $c->draw($rect);
     } else {
         $canvas = $image;
     }
     return $canvas;
 }
开发者ID:noccy80,项目名称:cherryphp,代码行数:20,代码来源:adaptivesharpen.php

示例14: applyFilter

 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);
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:21,代码来源:watermark.php

示例15: applyFilter

 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;
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:39,代码来源:reflection.php


注:本文中的Canvas类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。