
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
How to set the style for line drawing using imagesetstyle() function in PHP?
imagesetstyle() is an inbuilt function in PHP that is used to set the style for line drawing. It can be used by all line drawing functions like imagepolygon or imageline.
Syntax
bool imagesetstyle(resource $image, array $style)
Parameters
imagesetstyle() takes two parameters: $image and $style.
$image − Specifies the image resource to work on.
$style − Specifies the array of pixel colors.
Return Values
imagesetstyle() returns True on success or False on failure.
Example 1
<?php header("Content-type: image/jpeg"); $img = imagecreatetruecolor(700, 300); $w = imagecolorallocate($img, 122, 122, 122); $red = imagecolorallocate($img, 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($img, $style); imageline($img, 0, 0, 200, 200, 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($img, $style); $brush = imagecreatefrompng('C:\xampp\htdocs\Images\img34.png'); $w2 = imagecolorallocate($brush, 255, 255, 255); imagecolortransparent($brush, $w2); imagesetbrush($img, $brush); imageline($img, 200, 0, 0, 200, IMG_COLOR_STYLEDBRUSHED); imagejpeg($img); imagedestroy($img); ?>
Input Image
Output Image
Example 2
<?php // Load the png image using imagecreatefrompng() function. $img = imagecreatefrompng('C:\xampp\htdocs\Images\img34.png'); // Allocated the blue and green colors $blue = imagecolorallocate($img, 0, 0, 255); $green = imagecolorallocate($img, 0, 255, 0); // Draw a dashed line, 5 blue pixels, 5 white pixels $style = array($blue, $blue, $blue, $blue, $blue, $green, $green, $green, $green, $green); imagesetstyle($img, $style); imageline($img, 0, 100, 800, 100, IMG_COLOR_STYLED); // Output image to the browser header('Content-type: image/png'); imagepng($img); ?>
Output
- Related Articles
- How to set the image thickness for line drawing using imgesetthickness() function in PHP?
- How to set the tile image for filling using imagesettile() function in PHP?
- How to draw a line using imageline() function in PHP?
- Set the line style for the outline with CSS
- How to set a single pixel using imagesetpixel() function in PHP?
- PHP – Set the current setting for character encoding conversion using iconv_set_encoding() function
- How to set style for JTextPane in Java?
- PHP – How to set or get the default scale parameter for all bc math functions using bcscale() function?
- How to get or set the resolution of an image using imageresolution() function in PHP?
- How to set the style of the line in a text decoration with JavaScript?
- How to set the alpha blending flag to use layering effects using imaglayereffect() function in PHP?
- How to set the style of individual characters in IText using FabricJS?
- How to set the style of individual characters in Text using FabricJS?
- How to get the clipping rectangle using imagegetclip() function in PHP?
- How to set the style of controlling corners of Ellipse using FabricJS?

Advertisements