Example #1
0
<?php

$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();
Example #2
0
<?php

$sur = new CairoImageSurface(CairoFormat::ARGB32, 12, 12);
$con = new CairoContext($sur);
$source = $sur->createSimilar(CairoContent::COLOR_ALPHA, 12, 12);
$con2 = new CairoContext($source);
/* Fill the source surface with green */
$con2->setSourceRgb(0, 1, 0);
$con2->paint();
/* Draw a blue square in the middle of the source with clipping,
 * and leave the clip there. */
$con2->rectangle(12 / 4, 12 / 4, 12 / 2, 12 / 2);
$con2->clip();
$con2->setSourceRgb(0, 0, 1);
$con2->paint();
/* Fill the destination surface with solid red (should not appear
 * in final result) */
$con->setSourceRgb(1, 0, 0);
$con->paint();
/* Now draw the source surface onto the destination surface */
$con->setSourceSurface($source, 0, 0);
$con->paint();
$sur->writeToPng(dirname(__FILE__) . '/source-clip.png');
Example #3
0
 $con->rectangle($x, $y, $width, $height);
 $con->fill();
 $con->setOperator($op);
 $con->setSourceRgb(1, 0, 0);
 $con->moveTo($x, $y);
 $con->lineTo($x + $width, $y);
 $con->lineTo($x, $y + $height);
 $con->clip();
 switch ($i) {
     case 0:
         $wi = floor($width * 0.9);
         $he = floor($height * 0.9);
         $x += 0.05 * $width;
         $y += 0.05 * $height;
         //$stemp = $con->get_group_target();
         $msur = $sur->createSimilar(CairoContent::ALPHA, $wi, $he);
         $c2 = new CairoContext($msur);
         $c2->save();
         $c2->setSourceRgba(0, 0, 0, 0);
         $c2->setOperator(CairoOperator::SOURCE);
         $c2->paint();
         $c2->restore();
         $c2->setSourceRgb(1, 1, 1);
         $c2->arc(0.5 * $wi, 0.5 * $he, 0.45 * $he, 0, 2 * M_PI);
         $c2->fill();
         //unset($c2);
         $con->maskSurface($msur, $x, $y);
         //unset($msur);
         //unset($stemp);
         break;
     case 1:
Example #4
0
<?php

$sur = new CairoImageSurface(CairoFormat::ARGB32, 256 + 32 * 2, 192 + 32 * 2);
$con = new CairoContext($sur);
$s = new CairoImageSurface(CairoFormat::ARGB32, 100, 100);
$s->createFromPng(dirname(__FILE__) . "/romedalen.png");
//$s1 = new CairoImageSurface(FORMATARGB32,100, 100);
$s1 = $sur->createSimilar($sur->getContent(), 320, 256);
$con2 = new CairoContext($s1);
$con2->setSourceSurface($s, 32, 32);
$con2->setOperator(CairoOperator::SOURCE);
$pat = $con2->getSource();
$pat->setExtend(CairoExtend::REPEAT);
$con2->paint();
$con->setSourceSurface($s1, 0, 0);
$con->paint();
$sur->writeToPng(dirname(__FILE__) . "/extend-repeat-similar-php.png");
?>