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 25/11/2011, 14h11   #1
Membre à l'essai
 
Inscription : août 2010
Messages : 116
Détails du profil
Informations forums :
Inscription : août 2010
Messages : 116
Points : 22
Points : 22
Par défaut Fusionner deux images PNG

Bonjour les super héros,

J'ai besoin d'un code pour pouvoir fusionner deux images PNG, sans changer les dimensions de l'image (Principale) si ceux de l'image (LOGO dans notre cas) seront petit en WIDTH + HEIGHT, dans le cas ou le HEIGHT de l'image LOGO sera plus que celui de l'image PRINCIPALE là je veut avoir l'image de sortie avec le HEIGHT de l'image LOGO.

Ensuite l'enregistrer dans le serveur

A savoir que: IMAGE LOGO c'est celle que je veut fusionner sur l'IMAGE PRINCIPALE.

Le code que j'ai commencé:
Code :
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
 
<?php
 
list($width, $height, $type, $attr) = getimagesize("myImage1.png");
list($width1, $height1, $type1, $attr1) = getimagesize("myImage2.png");
 
$calcul_photo = $width * $height;
$calcul_logo = $width1 * $height1; 
 
if ($calcul_photo > $calcul_logo)
{
 
 
 
    header ("Content-type: image/png");
 
    $background = imagecreatefrompng("myImage2.png");
 
    $insert = imagecreatefrompng("myImage2.png");
 
    imagecolortransparent($insert,imagecolorat($insert,0,0));
 
    $insert_x = imagesx($insert);
    $insert_y = imagesy($insert);
 
    imagecopymerge($background,$insert,0,0,0,0,$insert_x,$insert_y,100);
 
    imagepng($background,"",100); 
}
else
{
  header ("Content-type: image/png");
 
    $background = imagecreatefrompng("myImage2.png");
 
    $insert = imagecreatefrompng("myImage1.png");
 
    imagecolortransparent($insert,imagecolorat($insert,0,0));
 
    $insert_x = imagesx($insert);
    $insert_y = imagesy($insert);
 
    imagecopymerge($background,$insert,0,0,0,0,$insert_x,$insert_y,100);
 
    imagepng($background,"",100); 
}
 
?>

Merci de m'aider.
NB: L'image ne s'affiche pas chez moi sur les navigateurs FIREFOX + OPERA + IE
Stalk3R est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/11/2011, 15h13   #2
Membre à l'essai
 
Inscription : août 2010
Messages : 116
Détails du profil
Informations forums :
Inscription : août 2010
Messages : 116
Points : 22
Points : 22
J'ai modifié mon code comme ça:
Code :
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
<?php
 
list($width, $height, $type, $attr) = getimagesize("myImage1.png");
list($width1, $height1, $type1, $attr1) = getimagesize("myImage2.png");
 
$calcul_photo = $width * $height;
$calcul_logo = $width1 * $height1; 
 
if ($calcul_photo > $calcul_logo)
{
header ("Content-type: image/png"); 
$MonCopyRight = imagecreatefrompng("myImage2.png"); 
$nxCopyRight = imagesx($MonCopyRight);$nyCopyRight = imagesy($MonCopyRight);
$Photo = imagecreatefrompng("myImage1.png");
$nxPhoto = imagesx($Photo);$nyPhoto = imagesy($Photo);
$placeX = 0;$placeY =  $nyPhoto - $nyCopyRight;
imagecopymerge($Photo, $MonCopyRight, $placeX, $placeY, 0, 0, $nxCopyRight, $nyCopyRight, 100);
imagepng($Photo);
}
else
{
header ("Content-type: image/png"); 
$MonCopyRight = imagecreatefrompng("myImage1.png"); 
$nxCopyRight = imagesx($MonCopyRight);$nyCopyRight = imagesy($MonCopyRight);
$Photo = imagecreatefrompng("myImage2.png");
$nxPhoto = imagesx($Photo);$nyPhoto = imagesy($Photo);
$placeX = 0;$placeY =  $nyPhoto - $nyCopyRight;
imagecopymerge($Photo, $MonCopyRight, $placeX, $placeY, 0, 0, $nxCopyRight, $nyCopyRight, 100);
imagepng($Photo);
}
 
?>
Ca prend pas en charge la transparence avec l'image résultante (Ce qui affiche directement une image noir à la place de la partie transparente).
Mais ça répond pas à mes questions que j'ai posté en haut
Stalk3R est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/01/2012, 23h34   #3
Membre Expert
 
Homme Eric Dureuil
Développeur informatique
Inscription : avril 2011
Messages : 874
Détails du profil
Informations personnelles :
Nom : Homme Eric Dureuil
Localisation : France, Isère (Rhône Alpes)

Informations professionnelles :
Activité : Développeur informatique
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : avril 2011
Messages : 874
Points : 1 361
Points : 1 361
salut,

il faut activer la transparence dans le résultat: imagesavealpha
__________________
Eric Dureuil, développeur web, c/c++, java indépendant
soyons
pensez à mettre et
ericd69 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 07h24.


 
 
 
 
Partenaires

Hébergement Web