(PHP 4, PHP 5)
imagesetpixel — Dessine un pixel
imagesetpixel() dessine un pixel aux coordonnées spécifiées.
Une ressource d'image, retourné par une des fonctions de création d'images, comme imagecreatetruecolor() .
X : coordonnée
Y : coordonnée
Un identifiant de couleur créé par la fonction imagecolorallocate()
Cette fonction retourne TRUE en cas de succès, FALSE en cas d'échec.
Exemple 1172. Exemple avec imagesetpixel()
Un dessin aléatoire qui se termine par une image régulière.
<?php
$x
=
200
;
$y
=
200
;
$gd
=
imagecreatetruecolor
(
$x
,
$y
);
$corners
[
0
] = array(
'x'
=>
100
,
'y'
=>
10
);
$corners
[
1
] = array(
'x'
=>
0
,
'y'
=>
190
);
$corners
[
2
] = array(
'x'
=>
200
,
'y'
=>
190
);
$red
=
imagecolorallocate
(
$gd
,
255
,
0
,
0
);
for (
$i
=
0
;
$i
<
100000
;
$i
++) {
imagesetpixel
(
$gd
,
round
(
$x
),
round
(
$y
),
$red
);
$a
=
rand
(
0
,
2
);
$x
= (
$x
+
$corners
[
$a
][
'x'
]) /
2
;
$y
= (
$y
+
$corners
[
$a
][
'y'
]) /
2
;
}
header
(
'Content-Type: image/png'
);
imagepng
(
$gd
);
?>
L'exemple ci-dessus va afficher quelque chose de similaire à :
imagecreatetruecolor() |
imagecolorallocate() |