<?php
    // sample to test the GD imgagebrush() function.
    // to view source call with: gd_brushes.php?viewsource=1
    // call f.e. with: gd_brushes.php?trans=1
    // v0.11 20-Sep-2004, by G. Knauf <efash@gmx.net>
    if ($_GET['viewsource']) {
        echo highlight_string(file_get_contents($_SERVER['SCRIPT_FILENAME']));
        die;
    }
    extension_loaded('gd') or die ("Error: GD extension not loaded!"); 
    $im = @ImageCreate (200, 200);
    $bg_color = ImageColorAllocate ($im, 255, 250, 205);
    $fg_color = ImageColorAllocate ($im, 0, 0, 255);
    if ($_GET['trans'])
        ImageColorTransparent($im, $bg_color);

    # Create a brush at an angle
    $diagonal_brush = @ImageCreate (5, 5);
    $white = ImageColorAllocate ($diagonal_brush, 255, 255, 255);
    $black = ImageColorAllocate ($diagonal_brush, 0, 0, 0);
    ImageColorTransparent($diagonal_brush, $white);
    ImageLine($diagonal_brush, 0, 4, 4, 0, $black); # NE diagonal

    # Set the brush
    ImageSetBrush ($im, $diagonal_brush);

    # Draw a circle using the brush
    ImageArc ($im, 100, 100, 125, 125, 0, 360, IMG_COLOR_BRUSHED);
    ImageArc ($im, 100, 100, 100, 100, 0, 360, $fg_color);

    # print the image to stdout
    Header("Content-type: image/png");
    ImagePng ($im);
    ImageDestroy ($im);
?>
Published in: PHP
Download

Related snippets