PHP
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

imagesettile> <imagesetstyle
Last updated: Fri, 10 Jul 2009

view this page in

imagesetthickness

(PHP 4 >= 4.0.6, PHP 5)

imagesetthicknessModifie l'épaisseur d'un trait

Description

bool imagesetthickness ( resource $image , int $thickness )

imagesetthickness() modifie l'épaisseur du trait des lignes de l'image image . Cette épaisseur intervient dans les dessins de polygones, ellipses, cercles, rectangles, etc. thickness est en pixels.

Liste de paramètres

image

Une ressource d'image, retourné par une des fonctions de création d'images, comme imagecreatetruecolor().

thickness

L'épaisseur, en pixels.

Valeurs de retour

Cette fonction retourne TRUE en cas de succès, FALSE en cas d'échec.

Exemples

Exemple #1 Exemple avec imagesetthickness()

<?php
// Création d'une image en 200x100
$im imagecreatetruecolor(200100);
$white imagecolorallocate($im0xFF0xFF0xFF);
$black imagecolorallocate($im0x000x000x00);

// Définit l'arrière-plan en blanc
imagefilledrectangle($im0029999$white);

// Définit l'épaisseur de la ligne à 5
imagesetthickness($im5);

// Dessine le rectangle
imagerectangle($im141418585$black);

// Affichage de l'image sur le navigateur
header('Content-Type: image/png');

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

L'exemple ci-dessus va afficher quelque chose de similaire à :

Notes

Note: Cette fonction requiert la bibliothèque GD 2.0.1 ou supérieure (2.0.28 ou supérieure est recommandée).



imagesettile> <imagesetstyle
Last updated: Fri, 10 Jul 2009
 
add a note add a note User Contributed Notes
imagesetthickness
jean-raymond dot chauviere at gmail dot com
30-Jun-2009 08:20
An easier to manage thickness is, before to draw in the ellipse to play with 2 ellipse with different color :

<?php
        imagefilledellipse 
($this->image,60,42,57,57,$drawColor);
       
imagefilledellipse  ($this->image,60,42,45,45,$backColor);
?>

The first line draw a filled ellipse with the wanted color, and the 2nd one, draw an ellipse with the background color from the same center, but is smaller.

The drawback of this method is that you erase everything in the middle of the ellipse.
admin at circle14 dot net
02-Feb-2009 01:33
Here is a custom function I wrote that addresses the line thickness issues with ellipses :

<?php
function draw_oval ($image, $pos_x, $pos_y, $elipse_width, $elipse_height, $color, $px_thick) {
   
$line = 0;
   
$thickness = $px_thick;
   
$elipse_w = $elipse_width;
   
$elipse_h = $elipse_height;
    while (
$line < $thickness) {
       
imageellipse($image, $pos_x, $pos_y, $elipse_w, $elipse_h, $color);
       
$line++;
       
$elipse_w--;
       
$elipse_h--;
    }
}
?>

I hope you find this useful.
bpatru at gmail dot com
28-Sep-2008 08:01
Apparently imagesetthickness doesn't work if antialiasing is set to true.
baldurien at bbnwn dot eu
12-Mar-2008 12:28
The way that imagesetthickness works with imagerectangle() is pretty strange.

<?php
imagesetthickness
(1);
imagerectangle($im, 10, 10, 50, 50, $red);
?>

This will draw a 41x41 square (because gd need the bottom right pixel, inclusive. 50 should get replaced by 49). This will "work" like:

<?php
imageline
($im, 10, 10, 10, 50, $red);
imageline($im, 10, 10, 50, 10, $red);
imageline($im, 50, 10, 50, 50, $red);
imageline($im, 10, 50, 50, 50, $red);
?>

The second example:

<?php
imagesetthickness
(2);
imagerectangle($im, 10, 10, 50, 50, $red);
?>

This will draw a 43x43 square because the border (thickness) is set to 2. *however* this is not a "regular" border of 2 pixels around the 41x41 original square!

On the left and right, there will be a thickness of 3, while there we be a thickness of 2.

If you take the imageline example, but set the thickness before to 2, this will *almost* do the trick: the left most pixel of the square will not be drawn.

To conclude:

1) do not forget that (width, height) of drawn rectangle is (x2-x1+1, y2-y1+1)
2) thickness is bad implemented (or at least, the behavior i s not documented) on rectangle, as the left/right thickness is not the wanted one.
3) 4*imageline() should do the trick, but after "patching" the top left pixel.
ab at cd dot com
27-Jun-2007 11:05
Note: Also, for me (working under PHP 5.0.2) this function ONLY seems to work with imageline...
-private-
28-Mar-2007 09:01
There is a known bug. Imagesetthickness is NOT working on ellipse.

imagesettile> <imagesetstyle
Last updated: Fri, 10 Jul 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites