search for in the  
<imagesetpixelimagesetthickness>
Last updated: Thu, 19 May 2005

imagesetstyle

(PHP 4 >= 4.0.6, PHP 5)

imagesetstyle -- Set the style for line drawing

Description

bool imagesetstyle ( resource image, array style )

imagesetstyle() sets the style to be used by all line drawing functions (such as imageline() and imagepolygon()) when drawing with the special color IMG_COLOR_STYLED or lines of images with color IMG_COLOR_STYLEDBRUSHED. Returns TRUE on success or FALSE on failure.

The style parameter is an array of pixels. Following example script draws a dashed line from upper left to lower right corner of the canvas:

Example 1. imagesetstyle() example

<?php
header
("Content-type: image/jpeg");
$im  = imagecreate(100, 100);
$w  = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);

/* Draw a dashed line, 5 red pixels, 5 white pixels */
$style = array($red, $red, $red, $red, $red, $w, $w, $w, $w, $w);
imagesetstyle($im, $style);
imageline($im, 0, 0, 100, 100, IMG_COLOR_STYLED);

/* Draw a line of happy faces using imagesetbrush() with imagesetstyle */
$style = array($w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $w, $red);
imagesetstyle($im, $style);

$brush = imagecreatefrompng("http://www.libpng.org/pub/png/images/smile.happy.png");
$w2 = imagecolorallocate($brush, 255, 255, 255);
imagecolortransparent($brush, $w2);
imagesetbrush($im, $brush);
imageline($im, 100, 0, 0, 100, IMG_COLOR_STYLEDBRUSHED);

imagejpeg($im);
imagedestroy($im);
?>

See also imagesetbrush(), imageline().

Note: This function was added in PHP 4.0.6



User Contributed Notes
imagesetstyle
yhoko at yhoko dot com
11-Aug-2004 08:24
When drawing lines that are >1px thick you'll have to setup the array corresponding to this fact (since there's no multi-array support for this function).

For example if the line's 3 pixels thick each 2nd color goes to the 2nd line, each 3rd color to the 3rd line and so on.
08-Aug-2001 04:49
The correct way to do dashed lines with transparent spaces between the dashes is to use the constant IMG_COLOR_TRANSPARENT instead of a color, like in this example:

$style=array($color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT );
ImageSetStyle($img, $style);
hatamoto at hhole dot com
27-Jul-2001 09:12
Okay, I answered my own question. ;)

If you use truecolor image modes and generate colors that have alpha values, those colors will be drawn correctly (ie: with appropriate transparency). So the following should draw a blue box with a white dashed line diagonally across it. It should NOT be a white solid line.

<?
$image
= imagecreatetruecolor(200,200);
imagealphablending($image, TRUE);
$blue = imagecolorallocate($image, 0, 0, 0xff);
$white = imagecolorallocate($image, 0xff, 0xff, 0xff);
$t = imagecolorresolvealpha($image, 0xff, 0xff, 0xff, 0xff);

$style = array($white, $white, $white, $t, $t, $t);

imagesetstyle($image, $style);
imagefilledrectangle($image, 0, 0, 199, 199, $blue);
imageline($image, 0, 0, 199, 199, IMG_COLOR_STYLED);

header("Content-type: image/jpeg");
imagejpeg($image);
?>

<imagesetpixelimagesetthickness>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT