Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > Images > GD
GD Forum d'entraide pour l'extension GD permettant de manipuler des images en PHP. Avant de poster -> tutoriels GD
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 28/02/2007, 20h43   #1
Membre éprouvé
 
Avatar de d-Rek
 
Développeur Web
Inscription : janvier 2007
Messages : 438
Détails du profil
Informations personnelles :
Localisation : France, Nord (Nord Pas de Calais)

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : janvier 2007
Messages : 438
Points : 400
Points : 400
Par défaut Fusion de PNG-24 Transparents

Bonsoir à tous,
Bon j'ai mis au point un générateur d'avatars.. See my Demo
J'arrive à fusionner des PNG-8bits sans prob mais je voudrais faire la même chose avec des PNG-24

Quelqu'un à une idée ?
PS : côté sécu de la variable POST elle est bidon pour le moment mais c'est un test

Code PHP :
1
2
3
4
5
6
7
8
9
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
<?
$id=1;
$yeux = $_POST['yeux'];
if(isset($yeux) AND $yeux!=""){
	$yeux = "yeux".$yeux.".png";
 
	//header ("Content-type: image/png"); // Afficher l'image | A virer pour l'export
 
	// On charge d'abord les images
	$_copyright = imagecreatefrompng("copyright.png"); // Copyright
	$_yeux = imagecreatefrompng($yeux); // Yeux
	$_visage = imagecreatefrompng("visage1.png"); // Visage
	$_fond = imagecreatefromjpeg("fond.jpg"); // Fond
 
	// On met le logo (yeux) dans l'image de visage (la photo)
	imagecopymerge($_fond, $_visage, 0, 0, 0, 0, 120, 120, 100);
	imagecopymerge($_fond, $_yeux, 0, 0, 0, 0, 120, 120, 100);
	imagecopymerge($_fond, $_copyright, 0, 0, 0, 0, 120, 120, 100);
	imagepng($_fond, $id.".png"); // imagepng($_fond, "1.png");  ----- Sans le second param, on affiche l'image | Avec on la crée sur le serveur
	//imagedestroy($_fond); // On détruit l'image... On libère de la mémoire ?
}
?>
<html>
<head>
<title>Créer son avatar</title>
<script type="text/javascript">
d = document;
function Show(quoi,qui){
	d.getElementById(quoi).src=quoi+qui+'.png';
}
</script>
<style type="text/css">
body{margin:50px 0 0 50px;}
img{border:0px;}
.tablo{width:400px; border:1px solid #BBBBBB; background-color:#D4D4D4;}
.tablo td{font-family:Trebuchet MS; font-size:12px; color:#5F5F5F;}
</style>
</head>
<body>
<table border="0" cellpadding="4" cellspacing="1" class="tablo">
	<tr>
		<td><img src="<? echo $id.".png";?>.png"></td>
		<td><b>VOTRE AVATAR ACTUEL</b></td>
	</tr>
	<tr>
		<td valign="top">
			<div style="width:120px; height:120px; overflow:none; border:1px solid #AAAAAA;">
				<div style="position:relative; top:0px; left:0px; z-index:15;"><img src="copyright.png" id="copyright"></div>
				<div style="position:relative; top:-120px; left:0px; z-index:10;"><img src="yeux1.png" id="yeux"></div>
				<div style="position:relative; top:-240px; left:0px; z-index:5;"><img src="visage1.png" id="visage"></div>
				<div style="position:relative; top:-360px; left:0px; z-index:0;"><img src="fond.jpg" id="fond"></div>
			</div>
		</td>
		<td valign="top">
			<form method="post" action="">
			<b>CREER UN AVATAR</b><br>
			<br>
			<label for="yeux1"><input type="radio" id="yeux1" name="yeux" value="1" OnClick="Show('yeux',1);" checked> Yeux1</label><br>
			<label for="yeux2"><input type="radio" id="yeux2" name="yeux" value="2" OnClick="Show('yeux',2);"> Yeux2</label><br>
			<br>
			<label for="visage"><input type="radio" id="visage1" name="visage" value="1" checked> Visage1</label><br>
			<br>
			<input type="submit" value="Créer">
			</form>
		</td>
	</tr>
</table>
</body>
</html>
d-Rek est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/03/2007, 23h17   #2
Membre éprouvé
 
Avatar de d-Rek
 
Développeur Web
Inscription : janvier 2007
Messages : 438
Détails du profil
Informations personnelles :
Localisation : France, Nord (Nord Pas de Calais)

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : janvier 2007
Messages : 438
Points : 400
Points : 400
Sur http://fr.php.net/manual/fr/function.imagepng.php, j'ai trouvé un bout de code :
Citation:
If you want to resize a png-24 image and preserve the alpha channel you need to set imagealphablending($im_dest, false) on the destination image just after creating it with imagecreatetruecolor() and do a imagesavealpha($im_dest, true) on it before saving it:

<?php
$im = ImageCreateFromPNG('redfade.png');

$im_dest = imagecreatetruecolor (500, 300);
imagealphablending($im_dest, false);

imagecopyresampled($im_dest, $im, 0, 0, 0, 0, 300, 300, 500, 300);

imagesavealpha($im_dest, true);
imagepng($im_re, 'small_redfade.png');

?>
Mais j'arrive à rien en faire.. je comprends pas pourquoi il fait ça..
imagecreatetruecolor renvoie une image noire !
d-Rek est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 18h42.


 
 
 
 
Partenaires

Hébergement Web