Vous êtes ici Codes PHP et MySQL > GD-Graphiques > Générer une image aléatoire de fond d'écran

 

Générer une image aléatoire de fond d'écran

Ce code source va vous permettre de créer une image aléatoire et ensuite vous pourrez par exemple la placer sur le fond de votre ecran. L'image est créée à partir de fonctions de la librairie GD.

Exemple de l'image qui va aléatoirement être crée.
C'est une image donc il faut afficher la page php comme une image en html.
L'image est crée à chaque affichage, mais elle peut être concervée dans le cache du navigateur donc pour éviter ça .
Si on veut un fond transparent : art_etoile.php?transp
Si on veut un fond noir : art_etoile.php?noir
 
Cam
Code vu 5892 fois
Enregistré le 04 Mars 2007
  • Digg ce code sur digg.com
  • Bookmark ce code sur del.icio.us
  • Bookmark ce code sur Google
  • Bookmark ce code sur Yahoo
  • Ajoute Générer une image aléatoire de fond d'écran
  • Partage ce code sur Facebook
 
 
 
 

Code Source


01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
 
<?php
/******************************************************************************/
/*                                                                            */
/*                       __        ____                                       */
/*                 ___  / /  ___  / __/__  __ _____________ ___               */
/*                / _ \/ _ \/ _ \_\ \/ _ \/ // / __/ __/ -_|_-<               */
/*               / .__/_//_/ .__/___/\___/\_,_/_/  \__/\__/___/               */
/*              /_/       /_/                                                 */
/*                                                                            */
/*                                                                            */
/******************************************************************************/
/*                                                                            */
/* Titre          : Générer une image aléatoire de fond d'écran               */
/*                                                                            */
/* URL            : http://www.phpsources.org/scripts255-PHP.htm              */
/* Auteur         : Cam                                                       */
/* Date édition   : 04 Mars 2007                                              */
/*                                                                            */
/******************************************************************************/
?>
   <?php
//
//*****************************************************************************

//*  ______  _____   _   _   _____   _   _        _____   _____       ___  ___*

//* |___  / | ____| | | | | |  _   | | | |      /  ___| /  _       /   |/   |
// HTTP://WWW.GENERATOR.ZEUBU.COM
//*    / /  | |__   | | | | | |_| | | | | |      | |     | | | |    / /|   /| |

//*   / /   |  __|  | | | | |  _  { | | | |      | |     | | | |   / / |__/ | |

//*  / /__  | |___  | |_| | | |_| | | |_| |  _   | |___  | |_| |  / /       | |

//* /_____| |_____| _____/ |_____/ _____/ |_|  _____| _____/ /_/        |_|
// CREATED BY CLEMENT VIALETTES
//*                                                                           
// *
//*****************************************************************************

//

Header('Content-type: image/png');

$img ImageCreate200200);

$colorbackgr ImageColorAllocate$img, , , );

//nombre de cercles
$u1 Rand1020);

for( $i=1$i $u1$i++)
{
  //couleurs
  $col1 Rand71255);
  $col2 Rand71255);
  $col3 Rand71255);

  //position des centres x y
  $a1 Rand( -5105);
  $a2 Rand( -5105);

  //largeur et hauteur x y
  $a3 Rand5150);
  $a4 Rand5150);

  //début du cercle et fin
  $deg1 Rand( , 360);
  $deg2 Rand( , 360);

  //type de cercle
  $a5 Rand( , 1);
  
  if($a5 == )
  {
    ImageArc$img$a1$a2$a3$a4$deg1$deg2ImageColorAllocate$img$col1$col2$col3));
    ImageArc$img$a1+1$a2+1$a3+1$a4+1$deg1+1$deg2-1ImageColorAllocate$img$col1-10$col2-10$col3-10));
    ImageArc$img$a1-1$a2-2$a3-1$a4-1$deg1+1$deg2-1ImageColorAllocate$img$col1-10$col2-10$col3-10));
    ImageArc$img$a1+2$a2+2$a3+2$a4+2$deg1+2$deg2-2ImageColorAllocate$img$col1-20$col2-20$col3-20));
    ImageArc$img$a1-2$a2-2$a3-2$a4-2$deg1+2$deg2-2ImageColorAllocate$img$col1-20$col2-20$col3-20));
    ImageArc$img$a1+3$a2+3$a3+3$a4+3$deg1+3$deg2-3ImageColorAllocate$img$col1-30$col2-30$col3-30));
    ImageArc$img$a1-3$a2-3$a3-3$a4-3$deg1+3$deg2-3ImageColorAllocate$img$col1-30$col2-30$col3-30));
    ImageArc$img$a1+4$a2+4$a3+4$a4+4$deg1+4$deg2-4ImageColorAllocate$img$col1-40$col2-40$col3-40));
    ImageArc$img$a1-4$a2-4$a3-4$a4-4$deg1+4$deg2-4ImageColorAllocate$img$col1-40$col2-40$col3-40));
    ImageArc$img$a1+5$a2+5$a3+5$a4+5$deg1+5$deg2-5ImageColorAllocate$img$col1-50$col2-50$col3-50));
    ImageArc$img$a1-5$a2-5$a3-5$a4-5$deg1+5$deg2-5ImageColorAllocate$img$col1-50$col2-50$col3-50));
    ImageArc$img$a1+6$a2+6$a3+6$a4+6$deg1+6$deg2-6ImageColorAllocate$img$col1-60$col2-60$col3-60));
    ImageArc$img$a1-6$a2-6$a3-6$a4-6$deg1+6$deg2-6ImageColorAllocate$img$col1-60$col2-60$col3-60));
    ImageArc$img$a1+7$a2+7$a3+7$a4+7$deg1+7$deg2-7ImageColorAllocate$img$col1-70$col2-70$col3-70));
    ImageArc$img$a1-7$a2-7$a3-7$a4-7$deg1+7$deg2-7ImageColorAllocate$img$col1-70$col2-70$col3-70));
  }
  else
  {
    ImageArc$img$a1$a2$a3$a4$deg1$deg2ImageColorAllocate$img$col1$col2$col3));
    ImageArc$img$a1+1*Rand(-1,1), $a2+1*Rand(-1,1), $a3+1*Rand(-1,1), $a4+1*
Rand(-1,1), $deg1+1$deg2-1ImageColorAllocate$img$col1-10$col2-10$col3-10));
    ImageArc$img$a1-1*Rand(-1,1), $a2-2*Rand(-1,1), $a3-1*Rand(-1,1), $a4-1*
Rand(-1,1), $deg1+1$deg2-1ImageColorAllocate$img$col1-10$col2-10$col3-10));
    ImageArc$img$a1+2*Rand(-1,1), $a2+2*Rand(-1,1), $a3+2*Rand(-1,1), $a4+2*
Rand(-1,1), $deg1+2$deg2-2ImageColorAllocate$img$col1-20$col2-20$col3-20));
    ImageArc$img$a1-2*Rand(-1,1), $a2-2*Rand(-1,1), $a3-2*Rand(-1,1), $a4-2*
Rand(-1,1), $deg1+2$deg2-2ImageColorAllocate$img$col1-20$col2-20$col3-20));
    ImageArc$img$a1+3*Rand(-1,1), $a2+3*Rand(-1,1), $a3+3*Rand(-1,1), $a4+3*
Rand(-1,1), $deg1+3$deg2-3ImageColorAllocate$img$col1-30$col2-30$col3-30));
    ImageArc$img$a1-3*Rand(-1,1), $a2-3*Rand(-1,1), $a3-3*Rand(-1,1), $a4-3*
Rand(-1,1), $deg1+3$deg2-3ImageColorAllocate$img$col1-30$col2-30$col3-30));
    ImageArc$img$a1+4*Rand(-1,1), $a2+4*Rand(-1,1), $a3+4*Rand(-1,1), $a4+4*
Rand(-1,1), $deg1+4$deg2-4ImageColorAllocate$img$col1-40$col2-40$col3-40));
    ImageArc$img$a1-4*Rand(-1,1), $a2-4*Rand(-1,1), $a3-4*Rand(-1,1), $a4-4*
Rand(-1,1), $deg1+4$deg2-4ImageColorAllocate$img$col1-40$col2-40$col3-40));
    ImageArc$img$a1+5*Rand(-1,1), $a2+5*Rand(-1,1), $a3+5*Rand(-1,1), $a4+5*
Rand(-1,1), $deg1+5$deg2-5ImageColorAllocate$img$col1-50$col2-50$col3-50));
    ImageArc$img$a1-5*Rand(-1,1), $a2-5*Rand(-1,1), $a3-5*Rand(-1,1), $a4-5*
Rand(-1,1), $deg1+5$deg2-5ImageColorAllocate$img$col1-50$col2-50$col3-50));
    ImageArc$img$a1+6*Rand(-1,1), $a2+6*Rand(-1,1), $a3+6*Rand(-1,1), $a4+6*
Rand(-1,1), $deg1+6$deg2-6ImageColorAllocate$img$col1-60$col2-60$col3-60));
    ImageArc$img$a1-6*Rand(-1,1), $a2-6*Rand(-1,1), $a3-6*Rand(-1,1), $a4-6*
Rand(-1,1), $deg1+6$deg2-6ImageColorAllocate$img$col1-60$col2-60$col3-60));
    ImageArc$img$a1+7*Rand(-1,1), $a2+7*Rand(-1,1), $a3+7*Rand(-1,1), $a4+7*
Rand(-1,1), $deg1+7$deg2-7ImageColorAllocate$img$col1-70$col2-70$col3-70));
    ImageArc$img$a1-7*Rand(-1,1), $a2-7*Rand(-1,1), $a3-7*Rand(-1,1), $a4-7*
Rand(-1,1), $deg1+7$deg2-7ImageColorAllocate$img$col1-70$col2-70$col3-70));
  }
}

//image 100x100 a été crée

//symétrie

$x = ;    $y = ;

while( $x <= 100)
{
  for( $y=; $y<=100$y++)
  {
    //image de droite
    ImageSetPixel$img200-($x), $yImageColorAt$img$x ,$y));

    //image dessous gauche
    ImageSetPixel$img$x200-$yImageColorAt$img$x$y));

    //image dessous droite
    ImageSetPixel$img200-$x200-$yImageColorAt$img$x$y));
  }
  $x++;
}

//transparent ?

if(isset($noir)==1);
elseif(isset($transp)==1)
  ImageColorTransparent$imgImageColorClosest$img, , , ));
else
{
  if( Rand(,1) == 1ImageColorTransparent$imgImageColorClosest$img, , , )
);
}

// On crée l'image

ImagePng($img);

// On libère l'espace mémoire alloué à l'image

ImageDestroy($img);

?>


 

Fonctions du code

: Envoie un en-tête HTTP - (PHP 4, PHP 5)
: Crée une nouvelle image à palette - (PHP 4, PHP 5)
: Alloue une couleur pour une image - (PHP 4, PHP 5)
: Génère une valeur aléatoire - (PHP 4, PHP 5)
: Dessine une ellipse partielle - (PHP 4, PHP 5)
: Retourne l'index de la couleur d'un pixel donné - (PHP 4, PHP 5)
: Dessine un pixel - (PHP 4, PHP 5)
: Détermine si une variable est affectée - (PHP 4, PHP 5)
: Retourne l'index de la couleur la plus proche d'une couleur donnée - (PHP...
: Définit la couleur transparente - (PHP 4, PHP 5)
: Envoie une image PNG vers un navigateur ou un fichier - (PHP 4, PHP 5)
: Détruit une image - (PHP 4, PHP 5)
Ajouter un commentaire
Code de sécurité

Attention: Les champs marqués d'une étoile * sont obligatoires
 
Librairie PHP

Connexion

 
 

GD-Graphiques

 
 

PHP

 
 
 
 
    Offres d'emploi

Plus de 500 offres d'emploi PHP/MySQL

Offres d'emploi
 
    Editeur PHP
 
        Publicité