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

Bibliothèques et frameworks PHP Discussion :

[ImageMagick] Création image transparente


Sujet :

Bibliothèques et frameworks PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé Avatar de alexmorel
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    196
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : Suisse

    Informations forums :
    Inscription : Septembre 2003
    Messages : 196
    Par défaut [ImageMagick] Création image transparente
    Bonjour,

    je voudrai cree une image transparent avec un texte par dessus qui utilise une police TTF


    Pour crée le tout avec une couleur pas de problème mais le rendre transparent soucis

    J'utilise se bout de code ...

    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
     
    session_start();
    ### Declare this script will be displayed as a PNG image.
    header("Content-type: image/png");
     
    ####################### BEGIN USER EDITS #######################
    $imagewidth = 500;
    $imageheight = 90;
    $fontsize = "30";
    $fontangle = "0";
    $font = "police.ttf";
    $text = 'Mon texte a afficher';
    $backgroundcolor = "E1ECF7";
    $textcolor = "000033";
    ######################## END USER EDITS ########################
     
    ### Convert HTML backgound color to RGB
    if( eregi( "([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})", $backgroundcolor, $bgrgb ) )
    {$bgred = hexdec( $bgrgb[1] );  $bggreen = hexdec( $bgrgb[2] );  $bgblue = hexdec( $bgrgb[3] );}
     
    ### Convert HTML text color to RGB
    if( eregi( "([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})", $textcolor, $textrgb ) )
    {$textred = hexdec( $textrgb[1] );  $textgreen = hexdec( $textrgb[2] );  $textblue = hexdec( $textrgb[3] );}
     
    ### Create image
    $im = imagecreate( $imagewidth, $imageheight );
     
    ### Declare image's background color
    $bgcolor = imagecolorallocate($im, $bgred,$bggreen,$bgblue);
     
    ### Declare image's text color
    $fontcolor = imagecolorallocate($im, $textred, $textgreen, $textblue);
     
    ### Get exact dimensions of text string
    $box = @imageTTFBbox($fontsize, $fontangle, $font, $text);
     
    ### Get width of text from dimensions
    $textwidth = abs($box[4] - $box[0]);
     
    ### Get height of text from dimensions
    $textheight = abs($box[5] - $box[1]);
     
    ### Get x-coordinate of centered text horizontally using length of the image and length of the text
    $xcord = ($imagewidth/2)-($textwidth/2)-2;
     
    ### Get y-coordinate of centered text vertically using height of the image and height of the text
    $ycord = ($imageheight/2-10)+($textheight/2);
     
    ### Declare completed image with colors, font, text, and text location
    imagettftext ($im, $fontsize, $fontangle, $xcord, $ycord, $fontcolor, $font, $text );
     
    ### Display completed image as PNG
    imagepng($im);
     
     
    ### Close the image
    imagedestroy($im);
    Voilà je trouve pas comment faire l'image de fond transparent et le texte de dessus de couleur..

    Merci

  2. #2
    Expert confirmé Avatar de Mr N.
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    5 418
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 5 418
    Par défaut
    Je te suggère de lire les commentaire de la doc :
    http://php.net/imagecreatetruecolor#66448

  3. #3
    Membre confirmé Avatar de alexmorel
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    196
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : Suisse

    Informations forums :
    Inscription : Septembre 2003
    Messages : 196
    Par défaut
    alors j'ai trouvé dans ta doc comment faire l'image de font transparent.

    Mais la qualité du texte diminue !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    /* En début de code */
    function imageCreateTransparent($x, $y, $red, $green, $blue) { 
       $imageOut = imagecreate($x, $y);
       $colourBlack = imagecolorallocate($imageOut, $red, $green, $blue);
       imagecolortransparent($imageOut, $colourBlack);
       return $imageOut;
    }
     
    $im = imageCreateTransparent($imagewidth, $imageheight, $textred, $textgreen, $textblue);
     
     
    ### Declare completed image with colors, font, text, and text location
    imagettftext ($im, $fontsize, $fontangle, $xcord, $ycord, $fontcolor, $font, $text );
    Mais là le texte donne moche et impressit.


    Merci d'avance

  4. #4
    Membre émérite
    Avatar de kankrelune
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    763
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 763
    Par défaut
    Il faut utiliser imagecreatetruecolor et non pas imagecreate et il faut utiliser une couleur que tu est sûr de ne pas retrouver dans ton texte (dans l'exemple le rose)... .. .

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    function imageCreateTransparent($x, $y) 
    { 
       $imageOut = imagecreatetruecolor($x, $y);
       $bg = imagecolorallocate($imageOut, 255,0,255)
       imagefill($imageout,$bg);
       imagecolortransparent($imageOut, 0, 0, $bg);
     
       return $imageOut;
    }
    @ tchaOo°

  5. #5
    Membre confirmé Avatar de alexmorel
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    196
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : Suisse

    Informations forums :
    Inscription : Septembre 2003
    Messages : 196
    Par défaut
    si je reprend ton code l'image est pas crée !

  6. #6
    Membre émérite
    Avatar de kankrelune
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    763
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 763
    Par défaut
    Fautes d'inattention...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    function imageCreateTransparent($x, $y) 
    { 
       $imageOut = imagecreatetruecolor($x, $y);
       $bg = imagecolorallocate($imageOut, 255,0,255);
       imagefill($imageOut, 0, 0, $bg);
       imagecolortransparent($imageOut, $bg);
       
       return $imageOut;
    }
    @ tchaOo°

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

Discussions similaires

  1. [ImageMagick] Création d'image avec des apostrophes
    Par Adaviada dans le forum Bibliothèques et frameworks
    Réponses: 9
    Dernier message: 05/07/2007, 12h35
  2. [GD] Création partie d'image transparente
    Par mussara dans le forum Bibliothèques et frameworks
    Réponses: 7
    Dernier message: 07/12/2006, 20h06
  3. [ImageMagick] Création d'une image miniature
    Par popeye82 dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 01/02/2006, 20h10
  4. [ImageMagick] Création d'image à la volée
    Par gdawirs dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 21/11/2005, 15h53
  5. [ImageMagick] Création de vignettes (images réduites)
    Par tom06440 dans le forum Bibliothèques et frameworks
    Réponses: 3
    Dernier message: 22/10/2005, 15h00

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