Génération alèatoire d'une image pouvant servir de fond d'écran.

Soyez le premier à donner votre avis sur cette source.

Vue 9 886 fois - Téléchargée 418 fois

Description

Exemple de l'image qui va aléatoirement être crée http://generator.zeubu.com/?id=generator_image_fond_ecran

C'est une image donc il faut afficher la page php comme une image en html :
<img src='http://generator.zeubu.com/generator_image/fond_ecran/art_etoile.php' border='0'>

L'image est crée à chaque affichage, mais elle peut être concervée dans le cache du navigateur donc pour éviter ça :
echo "<img src='http://generator.zeubu.com/generator_image/fond_ecran/art_etoile.php?".rand(0,99999)."' border='0'>";

Si on veut un fond transparent : art_etoile.php?transp
Si on veut un fond noir : art_etoile.php?noir
Si on veut un fond noir et flou : art_etoile.php?noir&flou
Si on veut un fond noir et trés flou : art_etoile.php?noir&flouplus
Si on veut un fond transparent et net : art_etoile.php?transp&net

Si les paramètres noir/transp et net/flou ne sont pas précisés, ils seront choisi au hasard (sauf flouplus).

Source / Exemple :


<?php
//
//*****************************************************************************
//*  ______  _____   _   _   _____   _   _        _____   _____       ___  ___*
//* |___  / | ____| | | | | |  _  \ | | | |      /  ___| /  _  \     /   |/   | HTTP://WWW.GENERATOR.ZEUBU.COM
//*    / /  | |__   | | | | | |_| | | | | |      | |     | | | |    / /|   /| |
//*   / /   |  __|  | | | | |  _  { | | | |      | |     | | | |   / / |__/ | |
//*  / /__  | |___  | |_| | | |_| | | |_| |  _   | |___  | |_| |  / /       | |
//* /_____| |_____| \_____/ |_____/ \_____/ |_|  \_____| \_____/ /_/        |_| CREATED BY CLEMENT VIALETTES
//*                                                                            *
//*****************************************************************************
//

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

$img = ImageCreate( 200, 200);

$colorbackgr = ImageColorAllocate( $img, 0, 0, 0);

//nombre de cercles
$u1 = Rand( 10, 20);

for( $i=1; $i < $u1; $i++)
{
	//couleurs
	$col1 = Rand( 71, 255);
	$col2 = Rand( 71, 255);
	$col3 = Rand( 71, 255);

	//position des centres x y
	$a1 = Rand( -5, 105);
	$a2 = Rand( -5, 105);

	//largeur et hauteur x y
	$a3 = Rand( 5, 150);
	$a4 = Rand( 5, 150);

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

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

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

//flou ?

if(isset($net)==1);
elseif(isset($flouplus)==1)
{

	$img2 = ImageCreate( 200, 200);
	
	Imagecopy($img2,$img,0,0,0,0,imagesx($img),imagesy($img));

	Imagecopymerge($img,$img2,0,0,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,0,1,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,0,2,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,0,3,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,0,4,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,1,0,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,1,1,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,1,2,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,1,3,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,1,4,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,2,0,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,2,1,0,0,imagesx($img),imagesy($img),50);
	
	Imagecopymerge($img,$img2,2,3,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,2,4,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,3,0,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,3,1,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,3,2,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,3,3,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,3,4,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,4,0,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,4,1,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,4,2,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,4,3,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,4,4,0,0,imagesx($img),imagesy($img),50);
	
	Imagecopymerge($img,$img2,2,2,0,0,imagesx($img),imagesy($img),50);

	ImageDestroy($img2);
}
	
elseif((isset($flou)==1)||(Rand(0,1) == 1))
{

	$img2 = ImageCreate( 200, 200);
	
	Imagecopy($img2,$img,0,0,0,0,imagesx($img),imagesy($img));

	Imagecopymerge($img,$img2,0,0,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,0,1,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,0,2,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,1,0,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,2,0,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,1,2,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,2,1,0,0,imagesx($img),imagesy($img),50);
	Imagecopymerge($img,$img2,2,2,0,0,imagesx($img),imagesy($img),50);

	Imagecopymerge($img,$img2,1,1,0,0,imagesx($img),imagesy($img),50);

	ImageDestroy($img2);
}
	
//symétrie

$x = 0;		$y = 0;

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

		//image dessous gauche
		ImageSetPixel( $img, $x, 200-$y, ImageColorAt( $img, $x, $y));

		//image dessous droite
		ImageSetPixel( $img, 200-$x, 200-$y, ImageColorAt( $img, $x, $y));
	}
	$x++;
}

//transparent ?

if(isset($noir)==1);
elseif((isset($transp)==1)||( Rand(0,1) == 1))
	ImageColorTransparent( $img, ImageColorClosest( $img, 0, 0, 0));

// On crée l'image

ImagePng($img);

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

ImageDestroy($img);

?>

Codes Sources

A voir également

Ajouter un commentaire Commentaires
cs_c v Messages postés 30 Date d'inscription vendredi 26 mars 2004 Statut Membre Dernière intervention 10 septembre 2012
4 mars 2007 à 12:27
Merci phpcs.com je vais pouvoir récupérer mon code en version colorié :)
coockiesch Messages postés 2268 Date d'inscription mercredi 27 novembre 2002 Statut Membre Dernière intervention 13 septembre 2013 4
4 mars 2007 à 14:09
Salut!
Y'a highlight_string qui le fait aussi ;)

@++

R@f
coockiesch Messages postés 2268 Date d'inscription mercredi 27 novembre 2002 Statut Membre Dernière intervention 13 septembre 2013 4
4 mars 2007 à 14:11
Sinon, c'est inutile mais marrant et assez joli, :)

@++

R@f
cs_c v Messages postés 30 Date d'inscription vendredi 26 mars 2004 Statut Membre Dernière intervention 10 septembre 2012
4 mars 2007 à 21:28
j'ai quand même récupéré les couleurs, j'y penserai la prochaine fois.
merci
cs_manouille Messages postés 73 Date d'inscription vendredi 29 août 2003 Statut Membre Dernière intervention 22 juin 2007
5 mars 2007 à 09:41
Marche pas sous firefox ...

sinon c'est rigolo :)

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.