PHP GD Style

GD Style

<?php
    // sample to test the GD imagesetstyle() function.
    // to view source call with: gd_styles.php?viewsource=1
    // call f.e. with: gd_styles.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);
    $black = ImageColorAllocate ($im, 0, 0, 0);
    $yellow = ImageColorAllocate ($im, 255, 255, 0);
    $blue = ImageColorAllocate ($im, 0, 0, 255);
    $green = ImageColorAllocate ($im, 0, 255, 0);
    $white = ImageColorAllocate ($im, 0, 0, 0);
    $transparent = ImageColorTransparent($im, $white);
    if ($_GET['trans'])
        $transparent = ImageColorTransparent($im, $black);

    # Set a style consisting of 4 pixels of yellow,
    # 4 pixels of blue, and a 2 pixel gap
    $style1 = array($yellow,$yellow,$yellow,$yellow,
            $blue,$blue,$blue,$blue,
            IMG_COLOR_TRANSPARENT,IMG_COLOR_TRANSPARENT);
    ImageSetStyle($im, $style1);

    # Draw a circle using the style
    ImageArc ($im, 100, 100, 125, 125, 0, 360, IMG_COLOR_STYLED);
    # Draw a horizontal line using the style
    ImageLine($im, 0, 20, 199, 20, IMG_COLOR_STYLED);
    # Draw a vertical line using the style
    ImageLine($im, 20, 0, 20, 199, IMG_COLOR_STYLED);

    # Set a style consisting of 5 pixels of green,
    # and a 2 pixel gap
    $style2 = array($green,$green,$green,$green,$green,
            IMG_COLOR_TRANSPARENT,IMG_COLOR_TRANSPARENT);
    ImageSetStyle($im, $style2);

    ImageLine($im, 100, 100, 199, 199, IMG_COLOR_STYLED);

/*
    # 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);
?>