imagesetstyle
Description
The imagesetstyle of Image for PHP set the style for line drawing.
Syntax
imagesetstyle(
GdImage $image,
array $style
): boolParameters
image
A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().
style
An array of pixel colors. You can use the IMG_COLOR_TRANSPARENT constant to add a transparent pixel.
Note: style must not be an empty array.
Return
Returns true on success or false on failure.
Examples
1 · return
<?
$width = 100;
$height = 100;
$image = imagecreate($width, $height);
$red = 255;
$green = 255;
$blue = 255;
$color = imagecolorallocate($image, $red, $green, $blue);
$style = array(
$color,
IMG_COLOR_TRANSPARENT
);
$return = imagesetstyle($image, $style);
var_export($return);
true
2 · base64 · dotted
<?
$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);
$red = 255;
$green = 255;
$blue = 255;
$color = imagecolorallocate($image, $red, $green, $blue);
$style = array(
$color,
IMG_COLOR_TRANSPARENT
);
imagesetstyle($image, $style);
$x1 = 0;
$y1 = 0;
$x2 = 100;
$y2 = 100;
$color = IMG_COLOR_STYLED;
imageline($image, $x1, $y1, $x2, $y2, $color);
ob_start();
imagepng($image);
$output = ob_get_clean();
echo '<!doctype html>
<html>
<body>
<img src="data:image/png;base64,' . base64_encode($output) . '">
</body>
</html>';
<!doctype html>
<html>
<body>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAkUlEQVR4nO3SMQEAMAwEofg3/dXQ4TbQwG07qPhFyS9KflHyi5JflPyi5Bclvyj5RckvSn5R8ouSX5T8ouQXJb8o+UXJL0p+UfKLkl+U/KLkFyW/KPlFyS9KflHyi5JflPyi5Bclvyj5RckvSn5R8ouSX5T8ouQXJb8o+UXJL0p+UfKLkl+U/KLkFyW/KPn17QEeLZVryrayjQAAAABJRU5ErkJggg==">
</body>
</html>3 · base64 · multicolor
<?
$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);
$red = 255;
$green = 0;
$blue = 0;
$color1 = imagecolorallocate($image, $red, $green, $blue);
$red = 255;
$green = 255;
$blue = 255;
$color2 = imagecolorallocate($image, $red, $green, $blue);
$red = 0;
$green = 0;
$blue = 255;
$color3 = imagecolorallocate($image, $red, $green, $blue);
$style = array(
$color1, $color1,
$color2, $color2,
$color3, $color3
);
imagesetstyle($image, $style);
$x1 = 0;
$y1 = 0;
$x2 = 100;
$y2 = 100;
$color = IMG_COLOR_STYLED;
imageline($image, $x1, $y1, $x2, $y2, $color);
ob_start();
imagepng($image);
$output = ob_get_clean();
echo '<!doctype html>
<html>
<body>
<img src="data:image/png;base64,' . base64_encode($output) . '">
</body>
</html>';
<!doctype html>
<html>
<body>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA5UlEQVR4nO3UMQEAAAyDsPk33WnITyRwcLuIepmtYqJeql6mXqJapl6m35t6qXqZeolqmXqZfm/qpepl6iWqZepl+r2pl6qXqZeolqmX6femXqpepl6iWqZept+beql6mXqJapl6mX5v6qXqZeolqmXqZfq9qZeql6mXqJapl+n3pl6qXqZeolqmXqbfm3qpepl6iWqZepl+b+ql6mXqJapl6mX6vamXqpepl6iWqZfp96Zeql6mXqJapl6m35t6qXqZeolqmXqZfm/qpepl6iWqZepl+r2pl6qXqZeolqmX6fdm2wM/oqdZ9nIEJAAAAABJRU5ErkJggg==">
</body>
</html>Links
Related
Image
- gd_info
- getimagesize
- getimagesizefromstring
- image_type_to_extension
- image_type_to_mime_type
- imageaffine
- imageaffinematrixconcat
- imageaffinematrixget
- imagealphablending
- imageantialias
- imagearc
- imageavif
- imagebmp
- imagechar
- imagecharup
- imagecolorallocate
- imagecolorallocatealpha
- imagecolorat
- imagecolorclosest
- imagecolorclosestalpha
- imagecolorclosesthwb
- imagecolordeallocate
- imagecolorexact
- imagecolorexactalpha
- imagecolormatch
- imagecolorresolve
- imagecolorresolvealpha
- imagecolorset
- imagecolorsforindex
- imagecolorstotal
- imagecolortransparent
- imageconvolution
- imagecopy
- imagecopymerge
- imagecopymergegray
- imagecopyresampled
- imagecopyresized
- imagecreate
- imagecreatefromavif
- imagecreatefrombmp
- imagecreatefromgif
- imagecreatefromjpeg
- imagecreatefrompng
- imagecreatefromstring
- imagecreatefromtga
- imagecreatefromwbmp
- imagecreatefromwebp
- imagecreatefromxbm
- imagecreatefromxpm
- imagecreatetruecolor
- imagecrop
- imagecropauto
- imagedashedline
- imagedestroy
- imageellipse
- imagefill
- imagefilledarc
- imagefilledellipse
- imagefilledpolygon
- imagefilledrectangle
- imagefilltoborder
- imagefilter
- imageflip
- imagefontheight
- imagefontwidth
- imageftbbox
- imagefttext
- imagegammacorrect
- imagegetclip
- imagegetinterpolation
- imagegif
- imageinterlace
- imageistruecolor
- imagejpeg
- imagelayereffect
- imageline
- imageloadfont
- imageopenpolygon
- imagepalettecopy
- imagepalettetotruecolor
- imagepng
- imagepolygon
- imagerectangle
- imageresolution
- imagerotate
- imagesavealpha
- imagescale
- imagesetbrush
- imagesetclip
- imagesetinterpolation
- imagesetpixel
- imagesetthickness
- imagesettile
- imagestring
- imagestringup
- imagesx
- imagesy
- imagetruecolortopalette
- imagettfbbox
- imagettftext
- imagetypes
- imagewbmp
- imagewebp
- imagexbm
- iptcembed
- iptcparse