IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Librairie GD afficher image dynamiquement


Sujet :

Langage PHP

  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Août 2012
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Chine

    Informations forums :
    Inscription : Août 2012
    Messages : 37
    Par défaut Librairie GD afficher image dynamiquement
    Salut à toues et à tous!

    Je me retrouve face à un problème que je n'arrive pas à résoudre. J'ai créé mon script qui me permet de créé un fond avec un texte grâce à la librairie GD. J'aimerai que l'image puisse être créé via un formulaire: un champ pour le texte et un autre pour le fond.
    Jusque là tout va bien. J'ai ma page avec mon formulaire qui renvoie vers le script, fabrique l'image et l'affiche. Le problème c'est quand je désire afficher le formulaire et la dernière image créé. Quelle est la méthode adéquate?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
     
    <body>
     
    <form action="font_page.php" method="post" name="form" title="form" lang="fr">.
     
    	<label for="fontColor">Couleur texte :</label>
        <select name="fontColor" id="fontColor">
          <option value="#ffffff" selected="selected">#ffffff</option>
          <option value="ffff00">#ffff00</option>
          <option value="ffff22">ffff22</option>
          <option value="ffff44">ffff44</option>
        </select>
     
    	<label for="fontBg">Couleur fond :</label>
        <select name="fontBg" id="fontBg">
          <option value="#ffffff" selected="selected">#ffffff</option>
          <option value="ffff00">#ffff00</option>
          <option value="ffff22">ffff22</option>
          <option value="ffff44">ffff44</option>
        </select>
     
    	<input name="submit" type="submit" value="Valider" />
     
    </form>
     
    <?php
     
    if (isset($_POST['submit']) AND isset($_POST['fontColor']) AND isset($_POST['fontBg']))
    {
     
    	header("Content-type: image/png");
     
    	//largeur et hauteur image en px
    	$x = 200;
    	$y = 50;
     
    	// couleur fond et texte
    	$hex_bg_color = $_POST['fontColor'];
    	$hex_txt_color = $_POST['fontBg'];
     
    	// variables fonction imagettftext
    	$txt_size = '20';
    	$angle = '0';
    	$txt_x = '35';
    	$txt_y = '30';
    	$font_file = 'fonts/Cabaletta.ttf';
    	$txt_sample = 'Voici un texte !';
     
    	// Image en vraies couleurs
    	$image = imagecreatetruecolor($x,$y);
     
    	//couleur du background
    	$red = hexdec(substr($hex_bg_color,0,2));
    	$green = hexdec(substr($hex_bg_color,2,4));
    	$blue = hexdec(substr($hex_bg_color,4,6));
    	$bg_color = imagecolorallocate($image,$red,$green,$blue);
    	imagefilledrectangle($image, 0, 0, $x, $y, $bg_color);
     
    	//couleur du texte
    	$rouge = hexdec(substr($hex_txt_color,0,2));
    	$vert = hexdec(substr($hex_txt_color,2,4));
    	$bleu = hexdec(substr($hex_txt_color,4,6));
    	$txt_color = imagecolorallocate($image,$rouge,$vert,$bleu);
     
    	putenv('GDFONTPATH='.realpath('.'));
     
    	imagettftext($image, $txt_size, $angle, $txt_x, $txt_y, $txt_color, $font_file, $txt_sample);
     
    	imagepng($image);
    	imagedestroy($image);
    }
    ?>
     
    </body>
    </html>
    Je vous remercie d'avance pour vos réponses!

  2. #2
    Membre émérite Avatar de patrickbaras
    Homme Profil pro
    Informaticien (à sa mémère).
    Inscrit en
    Septembre 2010
    Messages
    525
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : Belgique

    Informations professionnelles :
    Activité : Informaticien (à sa mémère).
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2010
    Messages : 525
    Par défaut
    faire

    imagepng($image,"nom_de_fichier_image.png"); en lieu est place de imagepng($image); et ajouter pour afficher l'image
    <img src="nom_de_fichier_image.png">

  3. #3
    Membre averti
    Homme Profil pro
    Inscrit en
    Août 2012
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Chine

    Informations forums :
    Inscription : Août 2012
    Messages : 37
    Par défaut
    Merci patrickbaras

    J'ai fais des essais encore instables mais je parviens au moins à afficher l'image.
    Dans mon code ci-dessous, le script m'affiche le formulaire ainsi que la dernière image créé (je ne sais pas d'où il la prend vu que je ne la stocke pas). Ce qui est très bien. Quand je complète mon formulaire et que je le valide, par contre j'ai plus rien qui s'affiche, juste le petit carré indiquant que l'image est manquante.

    Maintenant si je supprimer la ligne header("Content-type: image/png"); le comportement est différent. Le script fonctionne, la validation du formulaire et affichage de l'image aussi, par contre les couleurs sont fausses, on dirait que ce sont les couleurs en négatifs.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    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
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link href="colorPicker/css/style.css" rel="stylesheet" type="text/css" />
    <link href="colorPicker/css/reset.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="colorPicker/js/jquery-1.4.2.js"></script>
    <script type="text/javascript" src="colorPicker/js/jquery.simple-color.min.js"></script>
    <script  type="text/javascript">
    $(document).ready(function(){
    	$('.fontColor').simpleColor({
    			cellWidth: 9,
    			cellHeight: 9,
    			border: '1px solid #333333',
    			buttonClass: 'button',
    			displayColorCode: false
    	});	
    	$('.fontBg').simpleColor({
    			cellWidth: 9,
    			cellHeight: 9,
    			border: '1px solid #333333',
    			buttonClass: 'button',
    			displayColorCode: false
    	});	
    });
    </script>
    </head>
     
    <body>
     
    <form action="font_page.php" method="post" name="form" title="form" lang="fr">
        <label for="sampleText">Votre texte :</label>
        <input name="sampleText" type="text" size="20" />
        <label for="fontSize">Taille :</label>
        <select name="fontSize" id="fontSize">
          <option value="20" selected="selected">1</option>
          <option value="25">2</option>
          <option value="30">3</option>
          <option value="40">4</option>
        </select>
        <label for="fontColor">Couleur texte :</label>
        <input name="fontColor" class="fontColor" value="#ffffff"/>
        <label for="fontBg">couleur fond :</label>
        <input name="fontBg" class="fontBg" value="#000000"/>
        <input name="submit" type="submit" value="Valider" />
    </form>
     
    <p><img src="nom_de_fichier_image.png" /></p>
     
    <?php
     
    if (isset($_POST['submit']))
    {
     
    	header("Content-type: image/png");
     
    	$x = 200;
    	$y = 50;
    	$hex_bg_color = $_POST['fontBg'];
    	$hex_txt_color = $_POST['fontColor'];
     
    	$txt_size = $_POST['fontSize'];
    	$angle = '0';
    	$txt_x = '35';
    	$txt_y = '30';
    	$font_file = 'fonts/CAC Pinafore.ttf';
    	$txt_sample = 'Voici un texte !';
     
     
    	$image = imagecreatetruecolor($x,$y);
     
    	$red = hexdec(substr($hex_bg_color,0,2));
    	$green = hexdec(substr($hex_bg_color,2,4));
    	$blue = hexdec(substr($hex_bg_color,4,6));
    	$bg_color = imagecolorallocate($image,$red,$green,$blue);
    	imagefilledrectangle($image, 0, 0, $x, $y, $bg_color);
     
     
    	$rouge = hexdec(substr($hex_txt_color,0,2));
    	$vert = hexdec(substr($hex_txt_color,2,4));
    	$bleu = hexdec(substr($hex_txt_color,4,6));
    	$txt_color = imagecolorallocate($image,$rouge,$vert,$bleu);
     
    	putenv('GDFONTPATH='.realpath('.'));
     
    	imagettftext($image, $txt_size, $angle, $txt_x, $txt_y, $txt_color, $font_file, $txt_sample);
     
    	//imagepng($image);
    	imagepng($image,"nom_de_fichier_image.png");
     
    	//imagedestroy($image);
    }
    ?>
     
    </body>
    </html>
    Une idée de ce que je ne fais pas comme il faut? Merci d'avance!

  4. #4
    Membre émérite Avatar de patrickbaras
    Homme Profil pro
    Informaticien (à sa mémère).
    Inscrit en
    Septembre 2010
    Messages
    525
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : Belgique

    Informations professionnelles :
    Activité : Informaticien (à sa mémère).
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2010
    Messages : 525
    Par défaut
    tu ne peux envoyer dans la même page des "header" différent
    le header donne le type de document
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    dit que c'est du HTML

    header("Content-type: image/png");
    dit que c'est une image

    imagepng($image,"nom_de_fichier_image.png");
    stock ton image dans le fichier nom_de_fichier_image.png

    <img src='nom_de_fichier_image.png'> affiche le fichier

    voici une adaptation de ton code qui fonctionne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    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
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link href="colorPicker/css/style.css" rel="stylesheet" type="text/css" />
    <link href="colorPicker/css/reset.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="colorPicker/js/jquery-1.4.2.js"></script>
    <script type="text/javascript" src="colorPicker/js/jquery.simple-color.min.js"></script>
    <script  type="text/javascript">
    $(document).ready(function(){
    	$('.fontColor').simpleColor({
    			cellWidth: 9,
    			cellHeight: 9,
    			border: '1px solid #333333',
    			buttonClass: 'button',
    			displayColorCode: false
    	});	
    	$('.fontBg').simpleColor({
    			cellWidth: 9,
    			cellHeight: 9,
    			border: '1px solid #333333',
    			buttonClass: 'button',
    			displayColorCode: false
    	});	
    });
    </script>
    </head>
     
    <body>
     
    <form action="font_page.php" method="post" name="form" title="form" lang="fr">
        <label for="sampleText">Votre texte :</label>
        <input name="sampleText" type="text" size="20" />
        <label for="fontSize">Taille :</label>
        <select name="fontSize" id="fontSize">
          <option value="20" selected="selected">1</option>
          <option value="25">2</option>
          <option value="30">3</option>
          <option value="40">4</option>
        </select>
        <label for="fontColor">Couleur texte :</label>
        <input name="fontColor" class="fontColor" value="#ffffff"/>
        <label for="fontBg">couleur fond :</label>
        <input name="fontBg" class="fontBg" value="#000000"/>
        <input name="submit" type="submit" value="Valider" />
    </form>
     
    <p><img src="nom_de_fichier_image.png" /></p>
     
    <?php
     
    if (isset($_POST['submit']))
    {
     
    	//header("Content-type: image/png");
     
    	$x = 200;
    	$y = 50;
    	$hex_bg_color = $_POST['fontBg'];
    	$hex_txt_color = $_POST['fontColor'];
     
    	$txt_size = $_POST['fontSize'];
    	$angle = '0';
    	$txt_x = '35';
    	$txt_y = '30';
    	$font_file = 'fonts/CAC Pinafore.ttf';
    	$txt_sample = 'Voici un texte !';
     
     
    	$image = imagecreatetruecolor($x,$y);
     
    	$red = hexdec(substr($hex_bg_color,0,2));
    	$green = hexdec(substr($hex_bg_color,2,4));
    	$blue = hexdec(substr($hex_bg_color,4,6));
    	$bg_color = imagecolorallocate($image,$red,$green,$blue);
    	imagefilledrectangle($image, 0, 0, $x, $y, $bg_color);
     
     
    	$rouge = hexdec(substr($hex_txt_color,0,2));
    	$vert = hexdec(substr($hex_txt_color,2,4));
    	$bleu = hexdec(substr($hex_txt_color,4,6));
    	$txt_color = imagecolorallocate($image,$rouge,$vert,$bleu);
     
    	putenv('GDFONTPATH='.realpath('.'));
     
    	imagettftext($image, $txt_size, $angle, $txt_x, $txt_y, $txt_color, $font_file, $txt_sample);
     
    	//imagepng($image);
    	imagepng($image,"nom_de_fichier_image.png");
     
    	imagedestroy($image);
    }
    ?>
     
    </body>
    </html>

  5. #5
    Membre averti
    Homme Profil pro
    Inscrit en
    Août 2012
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Chine

    Informations forums :
    Inscription : Août 2012
    Messages : 37
    Par défaut
    merci encore patrickbaras, ça fonctionne avec cependant un petit problème qui fait que quand je sélectionne la couleur jaune, l'image créée un fond vert, le bleu cyan evient un bleu mauve, etc.
    Une idée d'où ça pourrait venir?
    Peut être de la transformation hexa en rgb, non?

  6. #6
    Membre émérite Avatar de patrickbaras
    Homme Profil pro
    Informaticien (à sa mémère).
    Inscrit en
    Septembre 2010
    Messages
    525
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : Belgique

    Informations professionnelles :
    Activité : Informaticien (à sa mémère).
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2010
    Messages : 525
    Par défaut
    effectivement tu a un soucis de conversion des couleurs

    substr($hex_bg_color,0,2) extrait de $hex_bg_color 2 caractères à partir de la position 0 (premier caractère)
    substr($hex_bg_color,2,4) extrait de $hex_bg_color 4 caractères à partir de la position 2
    (3ème caractère)
    substr($hex_bg_color,4,6) extrait de $hex_bg_color 6 caractères à partir de la position 4
    (5ème caractère)

    si $hex_bg_color contient "#123456" cela donne "#1" "2345" "56"
    tu doit donc changer

    substr($hex_bg_color,1,2) extrait 2 caractères à partir de la position 1 (deuxième caractère)
    substr($hex_bg_color,3,2) extrait 2 caractères à partir de la position 3 (quatrième caractère)
    substr($hex_bg_color,5,2) extrait 2 caractères à partir de la position 5 (sixième caractère)

    si $hex_bg_color contient "#123456" cela donne "12" "34" "56"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    /*
        $red = hexdec(substr($hex_bg_color,0,2));
        $green = hexdec(substr($hex_bg_color,2,4));
        $blue = hexdec(substr($hex_bg_color,4,6));
    */
        $red = hexdec(substr($hex_bg_color,1,2));
        $green = hexdec(substr($hex_bg_color,3,2));
        $blue = hexdec(substr($hex_bg_color,5,2));
     
        $bg_color = imagecolorallocate($image,$red,$green,$blue);
        imagefilledrectangle($image, 0, 0, $x, $y, $bg_color);
     
    /* 
        $rouge = hexdec(substr($hex_txt_color,0,2));
        $vert = hexdec(substr($hex_txt_color,2,4));
        $bleu = hexdec(substr($hex_txt_color,4,6));
    */
        $rouge = hexdec(substr($hex_txt_color,1,2));
        $vert = hexdec(substr($hex_txt_color,3,2));
        $bleu = hexdec(substr($hex_txt_color,5,2));

  7. #7
    Membre averti
    Homme Profil pro
    Inscrit en
    Août 2012
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Chine

    Informations forums :
    Inscription : Août 2012
    Messages : 37
    Par défaut
    Super, merci pour ton explication très claire qui m'a permit de comprendre mon problème. J'utilisais mal la fonction substr. Maintenant je vois très bien la chose.
    Un grand merci à toi pour ton aide!

  8. #8
    Membre émérite Avatar de patrickbaras
    Homme Profil pro
    Informaticien (à sa mémère).
    Inscrit en
    Septembre 2010
    Messages
    525
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : Belgique

    Informations professionnelles :
    Activité : Informaticien (à sa mémère).
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2010
    Messages : 525
    Par défaut
    de rien, n'oublie pas de mettre le post en "résolu"

  9. #9
    Membre averti
    Homme Profil pro
    Inscrit en
    Août 2012
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Chine

    Informations forums :
    Inscription : Août 2012
    Messages : 37
    Par défaut
    Juste un dernier conseil patrickbaras,
    Mes polices seront dans une table. Je voudrais faire une boucle qui permette d'afficher mes polices les unes à la suite. Le formulaire servirait à personnaliser la couleur du fond et du texte. Sachant cela, le nom de la police va se trouver dans ma boucle, ce qui veut dire que mon script de construction de l'image doit aussi faire partie de la boucle. Comment tu ferais ça? Je créé une fonction que j'appelle dans ma boucle pour effectuer la construction ou je créé un classe ou autre?
    Merci de tes précieux conseils!

  10. #10
    Membre émérite Avatar de patrickbaras
    Homme Profil pro
    Informaticien (à sa mémère).
    Inscrit en
    Septembre 2010
    Messages
    525
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : Belgique

    Informations professionnelles :
    Activité : Informaticien (à sa mémère).
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2010
    Messages : 525
    Par défaut
    je te conseille (mais c'est pas moi qui paye lol)

    tu crée une fonction ou tu passe texte,couleurs,nom du fichier fonts
    et qui génère un fichier avec un nom différent

    imagepng($image,"nom_de_fichier_image".$nom_du_font.".png");

    tu crée ta boucle de lecture dans la DB
    et dans la boucle
    tu appelle ta fonction
    puis tu affiche l'image
    en ajoutant un <img src='...'> du nom de l'image

  11. #11
    Membre averti
    Homme Profil pro
    Inscrit en
    Août 2012
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Chine

    Informations forums :
    Inscription : Août 2012
    Messages : 37
    Par défaut
    Hehe, super j'étais pas certain mais comme ça je le suis!

    Merci mille fois de ton aide!

  12. #12
    Membre émérite Avatar de patrickbaras
    Homme Profil pro
    Informaticien (à sa mémère).
    Inscrit en
    Septembre 2010
    Messages
    525
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : Belgique

    Informations professionnelles :
    Activité : Informaticien (à sa mémère).
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2010
    Messages : 525
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    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
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link href="colorPicker/css/style.css" rel="stylesheet" type="text/css" />
    <link href="colorPicker/css/reset.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="colorPicker/js/jquery-1.4.2.js"></script>
    <script type="text/javascript" src="colorPicker/js/jquery.simple-color.min.js"></script>
    <script  type="text/javascript">
    $(document).ready(function(){
        $('.fontColor').simpleColor({
                cellWidth: 9,
                cellHeight: 9,
                border: '1px solid #333333',
                buttonClass: 'button',
                displayColorCode: false
        });    
        $('.fontBg').simpleColor({
                cellWidth: 9,
                cellHeight: 9,
                border: '1px solid #333333',
                buttonClass: 'button',
                displayColorCode: false
        });    
    });
    </script>
    </head>
     
    <body>
     
    <form action="font_page.php" method="post" name="form" title="form" lang="fr">
        <label for="sampleText">Votre texte :</label>
        <input name="sampleText" type="text" size="20" value="sample text"/>
        <label for="fontSize">Taille :</label>
        <select name="fontSize" id="fontSize">
          <option value="20" selected="selected">1</option>
          <option value="25">2</option>
          <option value="30">3</option>
          <option value="40">4</option>
        </select>
        <label for="fontColor">Couleur texte :</label>
        <input name="fontColor" class="fontColor" value="#ffffff"/>
        <label for="fontBg">couleur fond :</label>
        <input name="fontBg" class="fontBg" value="#000000"/>
        <input name="submit" type="submit" value="Valider" />
    </form>
     
    <?php
    /*si on a recus des infos du formulaire*/ 
    if (isset($_POST['submit']))
    {
        $hex_bg_color = $_POST['fontBg'];
        $hex_txt_color = $_POST['fontColor'];
        $txt_size = $_POST['fontSize'];
        $txt_sample =  $_POST['sampleText'];
     
     
    /*on crée et affiche l'image pour VTKS embroidery.ttf*/
        $font_file='VTKS embroidery.ttf';
        $nom_image='VTKS embroidery.png';
     
        CreateImage($hex_bg_color,$hex_txt_color,$txt_size,$txt_sample,$font_file,$nom_image);
        echo "<p><img src='".$nom_image."'></p>";
     
    /*on crée et affiche l'image pour home sweet home outline.otf*/
        $font_file='home sweet home outline.otf';
        $nom_image='home sweet home outline.png';
     
        CreateImage($hex_bg_color,$hex_txt_color,$txt_size,$txt_sample,$font_file,$nom_image);
        echo "<p><img src='".$nom_image."'></p>";
     
    }
    ?> 
    <?php
    /*fonction de creation d'image*/
    function CreateImage($hex_bg_color,$hex_txt_color,$txt_size,$txt_sample,$font_file,$nom_image)
    {
        //header("Content-type: image/png");
     
        $x = 200;
        $y = 50;
        //$hex_bg_color = $_POST['fontBg'];
        //$hex_txt_color = $_POST['fontColor'];
     
        //$txt_size = $_POST['fontSize'];
        $angle = '0';
        $txt_x = '35';
        $txt_y = '30';
        //$font_file = 'fonts/CAC Pinafore.ttf';
        //$txt_sample = 'Voici un texte !';
     
        $image = imagecreatetruecolor($x,$y);
     
        $red = hexdec(substr($hex_bg_color,1,2));
        $green = hexdec(substr($hex_bg_color,3,2));
        $blue = hexdec(substr($hex_bg_color,5,2));
     
        $bg_color = imagecolorallocate($image,$red,$green,$blue);
        imagefilledrectangle($image, 0, 0, $x, $y, $bg_color);
     
        $rouge = hexdec(substr($hex_txt_color,1,2));
        $vert = hexdec(substr($hex_txt_color,3,2));
        $bleu = hexdec(substr($hex_txt_color,5,2));
     
        $txt_color = imagecolorallocate($image,$rouge,$vert,$bleu);
     
        putenv('GDFONTPATH='.realpath('.'));
     
        imagettftext($image, $txt_size, $angle, $txt_x, $txt_y, $txt_color, $font_file, $txt_sample);
     
        //imagepng($image);
        imagepng($image,$nom_image);
     
        imagedestroy($image);
    }
    ?>
     
    </body>
    </html>
    ensuite remplacer
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    /*on crée et affiche l'image pour VTKS embroidery.ttf*/
        $font_file='VTKS embroidery.ttf';
        $nom_image='VTKS embroidery.png';
     
        CreateImage($hex_bg_color,$hex_txt_color,$txt_size,$txt_sample,$font_file,$nom_image);
        echo "<p><img src='".$nom_image."'></p>";
     
    /*on crée et affiche l'image pour home sweet home outline.otf*/
        $font_file='home sweet home outline.otf';
        $nom_image='home sweet home outline.png';
     
        CreateImage($hex_bg_color,$hex_txt_color,$txt_size,$txt_sample,$font_file,$nom_image);
        echo "<p><img src='".$nom_image."'></p>";
    par ta boucle sur t'a db
    les noms de fonts correspondent a des fonts que j'ai évidement

  13. #13
    Membre averti
    Homme Profil pro
    Inscrit en
    Août 2012
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Chine

    Informations forums :
    Inscription : Août 2012
    Messages : 37
    Par défaut
    Merci beaucoup encore , je vais regarder ça de plus près.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Afficher images dynamiquement
    Par jojo_ol76 dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 09/03/2014, 12h11
  2. afficher image dynamique lightbox
    Par windows2056 dans le forum ASP.NET
    Réponses: 5
    Dernier message: 08/08/2011, 12h28
  3. Réponses: 2
    Dernier message: 17/02/2006, 14h26
  4. [Crystal Report] Afficher une image dynamiquement
    Par ntondini dans le forum SAP Crystal Reports
    Réponses: 1
    Dernier message: 09/08/2005, 10h58
  5. [VB.NET] Afficher une image dynamiquement
    Par Sadneth dans le forum ASP.NET
    Réponses: 20
    Dernier message: 07/01/2005, 17h26

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo