
- 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 image thickness for line drawing using imgesetthickness() function in PHP?
imagesetthickness() is an inbuilt function in PHP that is used to set the thickness for line drawing.
Syntax
bool imagesetthickness($image, $thickness)
Parameters
imagesetthickness() accepts two parameters− $image and $thickness.
$image − This parameter is returned by an image creation function such as imagecreatetruecolor(). It is used to create the size of an image.
$thickness − This parameter sets the thickness in pixel.
Return Values
imagesetthickness() returns True on success and False on failure.
Example 1
<?php // Create an image of a given size $img = imagecreatetruecolor(700, 300); $gray = imagecolorallocate($img, 0, 0, 255); $white = imagecolorallocate($img, 0xff, 0xff, 0xff); // Set the gray background color imagefilledrectangle($img, 0, 0, 700, 300, $gray); // Set the line thickness to 10 imagesetthickness($img, 10); // Draw the rectangle imagerectangle($img, 30, 30, 200, 150, $white); // Output image to the browser header('Content-Type: image/png'); imagepng($img); imagedestroy($img); ?>
Output
Example 2
<?php // Create an image of given size using imagecreatetruecolor() function $img = imagecreatetruecolor(700, 300); $blue = imagecolorallocate($img, 0, 0, 255); $white = imagecolorallocate($img, 0xff, 0xff, 0xff); // Set the white background-color imagefilledrectangle($img, 0, 0, 300, 200, $blue); // Set the line thickness to 50 imagesetthickness($img, 50); // Draw the white line imageline($img, 50, 50, 250, 50, $white); // Output image to the browser header('Content-Type: image/png'); imagepng($img); imagedestroy($img); ?>
Output
- Related Articles
- How to set the style for line drawing using imagesetstyle() function in PHP?
- How to set the tile image for filling using imagesettile() function in PHP?
- How to get or set the resolution of an image using imageresolution() function in PHP?
- How to destroy an image in PHP using imagedestroy() function?
- How to draw a line using imageline() function in PHP?
- How to ensure an image is a truecolor image using the imageistruecolor() function in PHP?
- How to crop an image automatically using imagecropauto() function in PHP?
- How to crop an image to the given rectangle using imagecrop() function using PHP?
- How to increase the line thickness of a Seaborn Line?
- How to set a single pixel using imagesetpixel() function in PHP?
- How to apply a filter to an image using imagefilter() function in PHP?
- PHP – Set the current setting for character encoding conversion using iconv_set_encoding() function
- How to copy the palette from one image to another using imagepalettecopy() function in PHP?
- Drawing an image in canvas using in JavaScript
- PHP – How to set or get the default scale parameter for all bc math functions using bcscale() function?

Advertisements