Manuel PHP

imagesetpixel

(PHP 4, PHP 5)

imagesetpixel — Dessine un pixel

Description

bool imagesetpixel ( resource $image , int $x , int $y , int $color )

imagesetpixel() dessine un pixel aux coordonnées spécifiées.

Liste de paramètres

image

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

x

X : coordonnée

y

Y : coordonnée

color

Un identifiant de couleur créé par la fonction imagecolorallocate()

Valeurs de retour

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

Exemples

Example#1 Exemple avec imagesetpixel()

Un dessin aléatoire qui se termine par une image régulière.

  1. <?php
  2.  
  3. $x = 200;  
  4. $y = 200;  
  5.  
  6. $gd = imagecreatetruecolor($x, $y);  
  7.  
  8. $corners[0] = array('x' => 100, 'y' => 10);  
  9. $corners[1] = array('x' => 0, 'y' => 190);  
  10. $corners[2] = array('x' => 200, 'y' => 190);  
  11.  
  12. $red = imagecolorallocate($gd, 255, 0, 0);  
  13.  
  14. for ($i = 0; $i < 100000; $i++) {  
  15. imagesetpixel($gd, round($x),round($y), $red);  
  16. $a = rand(0, 2);  
  17. $x = ($x + $corners[$a]['x']) / 2;  
  18. $y = ($y + $corners[$a]['y']) / 2;  
  19. }  
  20.  
  21. header('Content-Type: image/png');  
  22. imagepng($gd);  
  23.  
  24. ?> 

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


Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Breizh Blog