示例#1
0
function draw_pattern($surface_size)
{
    global $s;
    $con = new CairoContext($s);
    $con->setSourceRgb(1, 1, 1);
    $con->rectangle(0, 0, $surface_size / 2, $surface_size / 2);
    $con->fill();
    $con->setSourceRgb(1, 0, 0);
    $con->rectangle($surface_size / 2, 0, $surface_size / 2, $surface_size / 2);
    $con->fill();
    $con->setSourceRgb(0, 1, 0);
    $con->rectangle(0, $surface_size / 2, $surface_size / 2, $surface_size / 2);
    $con->fill();
    $con->setSourceRgb(0, 0, 1);
    $con->rectangle($surface_size / 2, $surface_size / 2, $surface_size / 2, $surface_size / 2);
    $con->fill();
    //	$s->writeToPng(dirname(__FILE__)  . "temp1.png");
}
示例#2
0
function draw_mask($x, $y)
{
    global $con, $width, $height, $sur;
    $wi = floor(0.9 * $width);
    $he = floor(0.9 * $height);
    $x += 0.05 * $width;
    $y += 0.05 * $height;
    //$s = new CairoImageSurface(FORMATARGB32, 1, 1);
    $s = $sur->createSimilar(CairoContent::ALPHA, $wi, $he);
    $con2 = new CairoContext($s);
    $con2->setSourceRgb(1, 1, 1);
    /* white */
    $con2->arc(0.5 * $wi, 0.5 * $he, 0.45 * $he, 0, 2 * M_PI);
    $con2->fill();
    $con->maskSurface($s, $x, $y);
}
示例#3
0
 /**
  * Draw an image 
  *
  * The image will be inlined in the SVG document using data URL scheme. For
  * this the mime type and base64 encoded file content will be merged to 
  * URL.
  * 
  * @param mixed $file Image file
  * @param ezcGraphCoordinate $position Top left position
  * @param mixed $width Width of image in destination image
  * @param mixed $height Height of image in destination image
  * @return void
  */
 public function drawImage($file, ezcGraphCoordinate $position, $width, $height)
 {
     $this->initiliazeSurface();
     // Ensure given bitmap is a PNG image
     $data = getimagesize($file);
     if ($data[2] !== IMAGETYPE_PNG) {
         throw new Exception('Cairo only has support for PNGs.');
     }
     // Create new surface from given bitmap
     $imageSurface = CairoImageSurface::createFromPng($file);
     // Create pattern from source image to be able to transform it
     $pattern = new CairoSurfacePattern($imageSurface);
     // Scale pattern to defined dimensions and move it to its destination position
     $matrix = CairoMatrix::multiply($move = CairoMatrix::initTranslate(-$position->x, -$position->y), $scale = CairoMatrix::initScale($data[0] / $width, $data[1] / $height));
     $pattern->setMatrix($matrix);
     // Merge surfaces
     $this->context->setSource($pattern);
     $this->context->rectangle($position->x, $position->y, $width, $height);
     $this->context->fill();
 }
示例#4
0
文件: sphere.php 项目: jamesan/cairo
<?php

$Surface = new CairoImageSurface(0, 256, 256);
$ctx = new CairoContext($Surface);
$ctx->setAntialias(0);
$ctx->setFillRule(0);
$ctx->scale(256 / 1.0, 256 / 1.0);
$pat = new CairoLinearGradient(0.0, 0.0, 0.0, 1.0);
$pat->addColorStopRgba(1, 0, 0, 0, 1);
$pat->addColorStopRgba(0, 1, 1, 1, 1);
$ctx->rectangle(0, 0, 1, 1);
$ctx->setSource($pat);
$ctx->fill();
$pat = new CairoRadialGradient(0.45, 0.4, 0.1, 0.4, 0.4, 0.5);
$pat->addColorStopRgba(0, 1, 1, 1, 1);
$pat->addColorStopRgba(1, 0, 0, 0, 1);
$ctx->setSource($pat);
$ctx->arc(0.5, 0.5, 0.3, 0, 2 * 3.14);
$ctx->fill();
$check = $ctx->getTarget();
$check->writeToPng(dirname(__FILE__) . '/sphere.png');
示例#5
0
$height = 64;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height);
$con = new CairoContext($sur);
$con->newPath();
$con->arc($width / 2, $height / 2, $width / 3, 0, 2 * M_PI);
$con->clip();
$con->newPath();
$con->moveTo(0, 0);
$con->lineTo($width / 4, $height / 2);
$con->lineTo(0, $height);
$con->lineTo($width, $height);
$con->lineTo(3 * $width / 4, $height / 2);
$con->lineTo($width, 0);
$con->closePath();
$con->clip();
$con->setSourceRgb(0, 0, 0.6);
$con->newPath();
$con->moveTo(0, 0);
$con->lineTo(0, $height);
$con->lineTo($width / 2, 3 * $height / 4);
$con->lineTo($width, $height);
$con->lineTo($width, 0);
$con->lineTo($width / 2, $height / 4);
$con->closePath();
$con->fill();
$con->newPath();
$con->arc($width / 2, $height / 2, $width / 5, 0, 2 * M_PI);
$con->clip();
$con->setSourceRgb(1, 1, 0);
$con->paint();
$sur->writeToPng(dirname(__FILE__) . "/clip-twice-php.png");
示例#6
0
<?php

$sur = new CairoImageSurface(CairoFormat::ARGB32, 36, 36);
$con = new CairoContext($sur);
$s = new CairoImageSurface(CairoFormat::ARGB32, 2, 2);
$con2 = new CairoContext($s);
$con2->setSourceRgb(1, 0, 0);
$con2->paint();
$con2->setSourceRgb(0, 0, 1);
$con2->rectangle(0, 1, 1, 1);
$con2->rectangle(1, 0, 1, 1);
$con2->fill();
$con->setSourceRgb(0, 0, 0);
$con->paint();
$con->save();
$con->translate(3, 3);
$con->scale(10, 10);
$con->translate(0.5, 0.5);
$con->setSourceSurface($s, 0, 0);
$con->paint();
$con->restore();
$sur->writeToPng(dirname(__FILE__) . "/filter-bilinear-extents-php.png");
?>


示例#7
0
$patwidth = 120;
$patheight = 120;
$size = $patwidth * 2;
$pad = 2;
$width = $pad + $size + $pad;
$height = $width;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height);
$con = new CairoContext($sur);
//$s = new CairoImageSurface(FORMATARGB32, $width, $height);
$con->translate($pad, $pad);
$pat_surface = $sur->createSimilar(CairoContent::COLOR_ALPHA, $patwidth, $patheight);
$cr2 = new CairoContext($pat_surface);
$cr2->setSourceRgba(1, 0, 1, 0.5);
$cr2->rectangle($patwidth / 6.0, $patheight / 6.0, $patwidth / 4.0, $patheight / 4.0);
$cr2->fill();
$cr2->setSourceRgba(0, 1, 1, 0.5);
$cr2->rectangle($patwidth / 2.0, $patheight / 2.0, $patwidth / 4.0, $patheight / 4.0);
$cr2->fill();
$cr2->setLineWidth(1);
$cr2->moveTo($patwidth / 6.0, 0);
$cr2->lineTo(0, 0);
$cr2->lineTo(0, $patheight / 6.0);
$cr2->setSourceRgb(1, 0, 0);
$cr2->stroke();
$cr2->moveTo($patwidth / 6.0, $patheight);
$cr2->lineTo(0, $patheight);
$cr2->lineTo(0, 5 * $patheight / 6.0);
$cr2->setSourceRgb(0, 1, 0);
$cr2->stroke();
$cr2->moveTo(5 * $patwidth / 6.0, 0);
示例#8
0
<?php

$s = new CairoImageSurface(CairoFormat::ARGB32, 100, 100);
$c = new CairoContext($s);
$c->setSourceRgb(0, 0, 0);
$c->paint();
$c->setLineWidth(1);
$c->setSourceRgb(1, 1, 1);
for ($r = 50; $r > 0; $r -= 10) {
    $c->arc(50, 50, $r, 0, 2 * M_PI);
    $c->stroke();
    $c->fill();
}
$s->writeToPng(dirname(__FILE__) . '/CairoContext__arc.png');
示例#9
0
<?php

$size = 100;
$border = 10;
$linewidth = 20;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $size, $size);
$con = new CairoContext($sur);
$s = $con->getGroupTarget();
$c = new CairoContext($s);
$c->moveTo($border, $border);
$c->lineTo($border + $linewidth, $border);
$c->lineTo($size - $border, $size - $border);
$c->lineTo($size - $border - $linewidth, $size - $border);
$c->clip();
$c->setSourceRgb(0, 0, 1);
$c->paint();
$c->setSourceRgb(1, 1, 1);
$c->rectangle($size / 2 - $linewidth / 2, $border, $linewidth, $size - 2 * $border);
$c->fill();
$c2 = new CairoContext($sur);
$c2->setSourceRgb(1, 1, 1);
$c2->rectangle($size - $border - $linewidth, $border, $linewidth, $size - 2 * $border);
$c2->fill();
$con->setSourceRgb(1, 1, 1);
$con->rectangle($border, $border, $linewidth, $size - 2 * $border);
$con->fill();
$sur->writeToPng(dirname(__FILE__) . "/clip-nesting-php.png");