2948 explained code solutions for 75 technologies


php-gdHow to set line thickness


While you can't directly set line thickness with gd, you can emulate thick lines by drawing multiple thin lines:

<?php

$im = imagecreatetruecolor(400, 300);

$c_black = imageColorAllocate($im, 0,0,0);
$c_green = imageColorAllocate($im, 46,204,64);

for ( $thick = 5; $thick > 0; $thick-- ) {
  imageline($im, 50, 50 + $thick, 350, 250 + $thick, $c_green);
}


imagePng($im, '/tmp/image.png');ctrl + c
imagecreatetruecolor

creates true color GD image object with specified width & height

imageColorAllocate

creates color object to later use in image

imageline

draws line using given coordinates and color

$thick = 5

resulting line thickness (5 in our case)

imagePng

saves image in PNG format to the given path


How to set line thickness, php gd

Usage example

<?php

$im = imagecreatetruecolor(400, 300);

$c_black = imageColorAllocate($im, 0,0,0);
$c_green = imageColorAllocate($im, 46,204,64);

for ( $thick = 5; $thick > 0; $thick-- ) {
  imageline($im, 50, 50 + $thick, 350, 250 + $thick, $c_green);
}

imagePng($im, '/tmp/image.png');