Exemplo n.º 1
0
if (gd_version() >= 2) {
    $im = imagecreatetruecolor($img_width, $img_height);
} else {
    $im = imagecreate($img_width, $img_height);
}
// No GD support, die.
if (!$im) {
    die("No GD support.");
}
// Fill the background with white
$bg_color = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg_color);
// Draw random circles, squares or lines?
$to_draw = my_rand(0, 2);
if ($to_draw == 1) {
    draw_circles($im);
} else {
    if ($to_draw == 2) {
        draw_squares($im);
    } else {
        draw_lines($im);
    }
}
// Draw dots on the image
draw_dots($im);
// Write the image string to the image
draw_string($im, $imagestring);
// Draw a nice border around the image
$border_color = imagecolorallocate($im, 0, 0, 0);
imagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $border_color);
// Output the image
Exemplo n.º 2
0
}
function draw_circles()
{
    global $con, $cisize;
    draw_circle(0, $cisize * -0.1);
    draw_circle($cisize * 0.4, $cisize * 0.25);
    draw_circle($cisize * 2, 0);
    draw_circle($cisize * 4, 0);
    draw_circle($cisize * 6, 0);
}
$sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height);
$con = new CairoContext($sur);
$con->translate($pad, $pad);
$con->setSourceRgb(0, 1, 0);
$con->setOperator(CairoOperator::OVER);
draw_circle($cisize * 0.5, $cisize * 1.5);
$con->setSourceRgb(1, 0, 0);
$con->setOperator(CairoOperator::ADD);
draw_circle($cisize * 0.75, $cisize * 1.75);
$con->setSourceRgb(0, 1, 0);
$con->setOperator(CairoOperator::OVER);
$con->translate($cisize * 2.5, $cisize * 0.6);
draw_circles();
$con->setSourceRgb(1, 0, 0);
$con->setOperator(CairoOperator::ADD);
$con->translate(0, $cisize * 2);
draw_circles();
$sur->writeToPng(dirname(__FILE__) . "/finer-grained-fallbacks-php.png");
?>