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 :

incruster un texte sur une image


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    158
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2004
    Messages : 158
    Par défaut incruster un texte sur une image
    Bonjour,

    Je souhaiterais ajouter un texte sur une image créée grâce à PhP et la librairie GD. La fonction ci-dessous créé l'image avec un degradé, mais je n'arrive pas à y incruster un simple texte...

    Auriez vous une idée ?

    Sur mon autre fichier j'appelle la fonction grâce à :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $image = new gd_gradient_fill($width,$height,$direction,$startcolor,$endcolor,$step);
    La class est :

    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
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    class gd_gradient_fill {
     
        // Constructor. Creates, fills and returns an image
        function gd_gradient_fill($w,$h,$d,$s,$e,$step=0) {
            $this->width = $w;
            $this->height = $h;
            $this->direction = $d;
            $this->startcolor = $s;
            $this->endcolor = $e;
            $this->step = intval(abs($step));
     
            // Attempt to create a blank image in true colors, or a new palette based image if this fails
            if (function_exists('imagecreatetruecolor')) {
                $this->image = imagecreatetruecolor($this->width,$this->height);
            } elseif (function_exists('imagecreate')) {
                $this->image = imagecreate($this->width,$this->height);
            } else {
                die('Unable to create an image');
            }
     
            // Fill it
            $this->fill($this->image,$this->direction,$this->startcolor,$this->endcolor);
     
            // Show it        
            $this->display($this->image);
     
            // Return it
            return $this->image;
        }
     
     
        // Displays the image with a portable function that works with any file type
        // depending on your server software configuration
        function display ($im) {
            if (function_exists("imagepng")) {
                header("Content-type: image/png");
                imagepng($im);
            }
            elseif (function_exists("imagegif")) {
                header("Content-type: image/gif");
                imagegif($im);
            }
            elseif (function_exists("imagejpeg")) {
                header("Content-type: image/jpeg");
                imagejpeg($im, "", 0.5);
            }
            elseif (function_exists("imagewbmp")) {
                header("Content-type: image/vnd.wap.wbmp");
                imagewbmp($im);
            } else {
                die("Doh ! No graphical functions on this server ?");
            }
            return true;
        }
     
     
        // The main function that draws the gradient
        function fill($im,$direction,$start,$end) {
     
            switch($direction) {
                case 'horizontal':
                    $line_numbers = imagesx($im);
                    $line_width = imagesy($im);
                    list($r1,$g1,$b1) = $this->hex2rgb($start);
                    list($r2,$g2,$b2) = $this->hex2rgb($end);
                    break;
                case 'vertical':
                    $line_numbers = imagesy($im);
                    $line_width = imagesx($im);
                    list($r1,$g1,$b1) = $this->hex2rgb($start);
                    list($r2,$g2,$b2) = $this->hex2rgb($end);				
                    break;
                case 'ellipse':
                    $width = imagesx($im);
                    $height = imagesy($im);
                    $rh=$height>$width?1:$width/$height;
                    $rw=$width>$height?1:$height/$width;
                    $line_numbers = min($width,$height);
                    $center_x = $width/2;
                    $center_y = $height/2;
                    list($r1,$g1,$b1) = $this->hex2rgb($end);
                    list($r2,$g2,$b2) = $this->hex2rgb($start);
                    imagefill($im, 0, 0, imagecolorallocate( $im, $r1, $g1, $b1 ));
                    break;
                case 'ellipse2':
                    $width = imagesx($im);
                    $height = imagesy($im);
                    $rh=$height>$width?1:$width/$height;
                    $rw=$width>$height?1:$height/$width;
                    $line_numbers = sqrt(pow($width,2)+pow($height,2));
                    $center_x = $width/2;
                    $center_y = $height/2;
                    list($r1,$g1,$b1) = $this->hex2rgb($end);
                    list($r2,$g2,$b2) = $this->hex2rgb($start);
                    break;
                case 'circle':
                    $width = imagesx($im);
                    $height = imagesy($im);
                    $line_numbers = sqrt(pow($width,2)+pow($height,2));
                    $center_x = $width/2;
                    $center_y = $height/2;
                    $rh = $rw = 1;
                    list($r1,$g1,$b1) = $this->hex2rgb($end);
                    list($r2,$g2,$b2) = $this->hex2rgb($start);
                    break;
                case 'circle2':
                    $width = imagesx($im);
                    $height = imagesy($im);
                    $line_numbers = min($width,$height);
                    $center_x = $width/2;
                    $center_y = $height/2;
                    $rh = $rw = 1;
                    list($r1,$g1,$b1) = $this->hex2rgb($end);
                    list($r2,$g2,$b2) = $this->hex2rgb($start);
                    imagefill($im, 0, 0, imagecolorallocate( $im, $r1, $g1, $b1 ));
                    break;
                case 'square':
                case 'rectangle':
                    $width = imagesx($im);
                    $height = imagesy($im);
                    $line_numbers = max($width,$height)/2;
                    list($r1,$g1,$b1) = $this->hex2rgb($end);
                    list($r2,$g2,$b2) = $this->hex2rgb($start);
                    break;
                case 'diamond':
                    list($r1,$g1,$b1) = $this->hex2rgb($end);
                    list($r2,$g2,$b2) = $this->hex2rgb($start);
                    $width = imagesx($im);
                    $height = imagesy($im);
                    $rh=$height>$width?1:$width/$height;
                    $rw=$width>$height?1:$height/$width;
                    $line_numbers = min($width,$height);
                    break;
                default:
            }
     
            for ( $i = 0; $i < $line_numbers; $i=$i+1+$this->step ) {
                // old values :
                $old_r=$r;
                $old_g=$g;
                $old_b=$b;
                // new values :
                $r = ( $r2 - $r1 != 0 ) ? intval( $r1 + ( $r2 - $r1 ) * ( $i / $line_numbers ) ): $r1;
                $g = ( $g2 - $g1 != 0 ) ? intval( $g1 + ( $g2 - $g1 ) * ( $i / $line_numbers ) ): $g1;
                $b = ( $b2 - $b1 != 0 ) ? intval( $b1 + ( $b2 - $b1 ) * ( $i / $line_numbers ) ): $b1;
                // if new values are really new ones, allocate a new color, otherwise reuse previous color.
                // There's a "feature" in imagecolorallocate that makes this function
                // always returns '-1' after 255 colors have been allocated in an image that was created with
                // imagecreate (everything works fine with imagecreatetruecolor)
                if ( "$old_r,$old_g,$old_b" != "$r,$g,$b") 
                    $fill = imagecolorallocate( $im, $r, $g, $b );
                switch($direction) {
                    case 'vertical':
                        imagefilledrectangle($im, 0, $i, $line_width, $i+$this->step, $fill);
                        break;
                    case 'horizontal':
                        imagefilledrectangle( $im, $i, 0, $i+$this->step, $line_width, $fill );
                        break;
                    case 'ellipse':
                    case 'ellipse2':
                    case 'circle':
                    case 'circle2':
                        imagefilledellipse ($im,$center_x, $center_y, ($line_numbers-$i)*$rh, ($line_numbers-$i)*$rw,$fill);
                        break;
                    case 'square':
                    case 'rectangle':
                        imagefilledrectangle ($im,$i*$width/$height,$i*$height/$width,$width-($i*$width/$height), $height-($i*$height/$width),$fill);
                        break;
                    case 'diamond':
                        imagefilledpolygon($im, array (
                            $width/2, $i*$rw-0.5*$height,
                            $i*$rh-0.5*$width, $height/2,
                            $width/2,1.5*$height-$i*$rw,
                            1.5*$width-$i*$rh, $height/2 ), 4, $fill);
                        break;
                    default:    
                }        
            }
        }
     
        // #ff00ff -> array(255,0,255) or #f0f -> array(255,0,255)
        function hex2rgb($color) {
            $color = str_replace('#','',$color);
            $s = strlen($color) / 3;
            $rgb[]=hexdec(str_repeat(substr($color,0,$s),2/$s));
            $rgb[]=hexdec(str_repeat(substr($color,$s,$s),2/$s));
            $rgb[]=hexdec(str_repeat(substr($color,2*$s,$s),2/$s));
            return $rgb;
        }
    }

  2. #2
    Membre émérite
    Avatar de amoiraud
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2006
    Messages
    606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

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

    Informations forums :
    Inscription : Octobre 2006
    Messages : 606
    Par défaut
    Utilise la fonction imageftext()
    PS : Un petit tour sur le manuel de la librairie GD permet de trouver la bonne fonction

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    158
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2004
    Messages : 158
    Par défaut
    Salut Amoiraud,

    Merci mais j'avais bien sur déjà essayé sinon je ne vous aurais pas sollicité

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    //appel de la class et des variables
    require_once('class/gd-gradient-fill.php');
     
    	$width = 500;
    	$height = 200;
    	$direction = vertical;
    	$startcolor = "#000000";
    	$endcolor = "#cccccc";
    	$step = 0;
    	$image = new gd_gradient_fill($width,$height,$direction,$startcolor,$endcolor,$step);
     
    //Créer l'image
    imagettftext($image, $size, $angle, $x, $y, $text_color, $font_file, $text);
    Mais cela ne marche pas. ça crée uniquement le dégradé

  4. #4
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    a moins que je ne me trompe :
    - gd_gradient_fill() est une fonction.
    - l'image est crée DANS cette fonction
    - EN DEHORS de la fonction, la "ressource d'image" n'est plus disponible (je pense)

    Essaie en mettant A L'INTERIEUR de ta fonction gd_gradient_fill() :
    imagettftext(...);

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    158
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2004
    Messages : 158
    Par défaut
    Comme ça (ci-dessous incruster dans la class), ça ne marche pas :


    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
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    	// Constructor. Creates, fills and returns an image
    	function gd_gradient_fill($w,$h,$d,$s,$e,$step=0) {
    		$this->width = $w;
    		$this->height = $h;
    		$this->direction = $d;
    		$this->startcolor = $s;
    		$this->endcolor = $e;
    		$this->step = intval(abs($step));
     
    		// Attempt to create a blank image in true colors, or a new palette based image if this fails
    		if (function_exists('imagecreatetruecolor')) {
    			$this->image = imagecreatetruecolor($this->width,$this->height);
    		} elseif (function_exists('imagecreate')) {
    			$this->image = imagecreate($this->width,$this->height);
    		} else {
    			die('Unable to create an image');
    		}
     
    		// Fill it
    		$this->fill($this->image,$this->direction,$this->startcolor,$this->endcolor);
     
    		imagettftext($image, $size, $angle, $x, $y, $text_color, $font_file, $text);
     
    		// Show it		
    		$this->display($this->image);
     
    		// Return it
    		return $this->image;
    	}
     
    	// Displays the image with a portable function that works with any file type
    	// depending on your server software configuration
    	function display ($im) {
    		if (function_exists("imagepng")) {
    			header("Content-type: image/png");
    			imagepng($im);
    		}
    		elseif (function_exists("imagegif")) {
    			header("Content-type: image/gif");
    			imagegif($im);
    		}
    		elseif (function_exists("imagejpeg")) {
    			header("Content-type: image/jpeg");
    			imagejpeg($im, "", 0.5);
    		}
    		elseif (function_exists("imagewbmp")) {
    			header("Content-type: image/vnd.wap.wbmp");
    			imagewbmp($im);
    		} else {
    			die("Doh ! No graphical functions on this server ?");
    		}
    		return true;
    	}
     
     
    	// The main function that draws the gradient
    	function fill($im,$direction,$start,$end) {
     
    		switch($direction) {
    			case 'horizontal':
    				$line_numbers = imagesx($im);
    				$line_width = imagesy($im);
    				list($r1,$g1,$b1) = $this->hex2rgb($start);
    				list($r2,$g2,$b2) = $this->hex2rgb($end);
    				break;
    			case 'vertical':
    				$line_numbers = imagesy($im);
    				$line_width = imagesx($im);
    				list($r1,$g1,$b1) = $this->hex2rgb($start);
    				list($r2,$g2,$b2) = $this->hex2rgb($end);
    				break;
    			case 'ellipse':
    				$width = imagesx($im);
    				$height = imagesy($im);
    				$rh=$height>$width?1:$width/$height;
    				$rw=$width>$height?1:$height/$width;
    				$line_numbers = min($width,$height);
    				$center_x = $width/2;
    				$center_y = $height/2;
    				list($r1,$g1,$b1) = $this->hex2rgb($end);
    				list($r2,$g2,$b2) = $this->hex2rgb($start);
    				imagefill($im, 0, 0, imagecolorallocate( $im, $r1, $g1, $b1 ));
    				break;
    			case 'ellipse2':
    				$width = imagesx($im);
    				$height = imagesy($im);
    				$rh=$height>$width?1:$width/$height;
    				$rw=$width>$height?1:$height/$width;
    				$line_numbers = sqrt(pow($width,2)+pow($height,2));
    				$center_x = $width/2;
    				$center_y = $height/2;
    				list($r1,$g1,$b1) = $this->hex2rgb($end);
    				list($r2,$g2,$b2) = $this->hex2rgb($start);
    				break;
    			case 'circle':
    				$width = imagesx($im);
    				$height = imagesy($im);
    				$line_numbers = sqrt(pow($width,2)+pow($height,2));
    				$center_x = $width/2;
    				$center_y = $height/2;
    				$rh = $rw = 1;
    				list($r1,$g1,$b1) = $this->hex2rgb($end);
    				list($r2,$g2,$b2) = $this->hex2rgb($start);
    				break;
    			case 'circle2':
    				$width = imagesx($im);
    				$height = imagesy($im);
    				$line_numbers = min($width,$height);
    				$center_x = $width/2;
    				$center_y = $height/2;
    				$rh = $rw = 1;
    				list($r1,$g1,$b1) = $this->hex2rgb($end);
    				list($r2,$g2,$b2) = $this->hex2rgb($start);
    				imagefill($im, 0, 0, imagecolorallocate( $im, $r1, $g1, $b1 ));
    				break;
    			case 'square':
    			case 'rectangle':
    				$width = imagesx($im);
    				$height = imagesy($im);
    				$line_numbers = max($width,$height)/2;
    				list($r1,$g1,$b1) = $this->hex2rgb($end);
    				list($r2,$g2,$b2) = $this->hex2rgb($start);
    				break;
    			case 'diamond':
    				list($r1,$g1,$b1) = $this->hex2rgb($end);
    				list($r2,$g2,$b2) = $this->hex2rgb($start);
    				$width = imagesx($im);
    				$height = imagesy($im);
    				$rh=$height>$width?1:$width/$height;
    				$rw=$width>$height?1:$height/$width;
    				$line_numbers = min($width,$height);
    				break;
    			default:
    		}
     
    		for ( $i = 0; $i < $line_numbers; $i=$i+1+$this->step ) {
    			// old values :
    			$old_r=$r;
    			$old_g=$g;
    			$old_b=$b;
    			// new values :
    			$r = ( $r2 - $r1 != 0 ) ? intval( $r1 + ( $r2 - $r1 ) * ( $i / $line_numbers ) ): $r1;
    			$g = ( $g2 - $g1 != 0 ) ? intval( $g1 + ( $g2 - $g1 ) * ( $i / $line_numbers ) ): $g1;
    			$b = ( $b2 - $b1 != 0 ) ? intval( $b1 + ( $b2 - $b1 ) * ( $i / $line_numbers ) ): $b1;
    			// if new values are really new ones, allocate a new color, otherwise reuse previous color.
    			// There's a "feature" in imagecolorallocate that makes this function
    			// always returns '-1' after 255 colors have been allocated in an image that was created with
    			// imagecreate (everything works fine with imagecreatetruecolor)
    			if ( "$old_r,$old_g,$old_b" != "$r,$g,$b") 
    				$fill = imagecolorallocate( $im, $r, $g, $b );
    			switch($direction) {
    				case 'vertical':
    					imagefilledrectangle($im, 0, $i, $line_width, $i+$this->step, $fill);
    					break;
    				case 'horizontal':
    					imagefilledrectangle( $im, $i, 0, $i+$this->step, $line_width, $fill );
    					break;
    				case 'ellipse':
    				case 'ellipse2':
    				case 'circle':
    				case 'circle2':
    					imagefilledellipse ($im,$center_x, $center_y, ($line_numbers-$i)*$rh, ($line_numbers-$i)*$rw,$fill);
    					break;
    				case 'square':
    				case 'rectangle':
    					imagefilledrectangle ($im,$i*$width/$height,$i*$height/$width,$width-($i*$width/$height), $height-($i*$height/$width),$fill);
    					break;
    				case 'diamond':
    					imagefilledpolygon($im, array (
    						$width/2, $i*$rw-0.5*$height,
    						$i*$rh-0.5*$width, $height/2,
    						$width/2,1.5*$height-$i*$rw,
    						1.5*$width-$i*$rh, $height/2 ), 4, $fill);
    					break;
    				default:	
    			}		
    		}
    	}
     
    	// #ff00ff -> array(255,0,255) or #f0f -> array(255,0,255)
    	function hex2rgb($color) {
    		$color = str_replace('#','',$color);
    		$s = strlen($color) / 3;
    		$rgb[]=hexdec(str_repeat(substr($color,0,$s),2/$s));
    		$rgb[]=hexdec(str_repeat(substr($color,$s,$s),2/$s));
    		$rgb[]=hexdec(str_repeat(substr($color,2*$s,$s),2/$s));
    		return $rgb;
    	}
    }

  6. #6
    Membre émérite

    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2011
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 411
    Par défaut
    Normal, dans
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    imagettftext($image, $size, $angle, $x, $y, $text_color, $font_file, $text);
    Aucune des variables ne sont définies...

    Si tu as une police .ttf sur ton serveur, j'imagine que déjà, tu souhaiterais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    $font = "arial.ttf";
    $textcolor = imagecolorallocate($this->image, 0, 0, 255); // bleu
    imagettftext($this->image, 12, 0, 0, 0, $textcolor , $font ,  "hello world" );
    Bien sur, cela mettra sur $this->image, un texte "hello world" de taille 12px de gauche à droite en haut à gauche de l'image avec la police Arial présente dans le même dossier que ta classe PHP... à toi de modifier en lisant le manuel : http://www.php.net/manual/en/function.imagettftext.php

    Sinon, utilise imagestring() à la place:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $textcolor = imagecolorallocate($this->image, 0, 0, 255); // bleu
    imagestring( $this->image , 2 , 0 , 0 , "hello world" , $textcolor  );
    Cela mettra sur $this->image, un texte "hello world" de taille 2 (taille entre 1 et 5 à tester) de gauche à droite en haut à gauche de l'image avec une police prédéfinie par PHP (et GD)... à toi de modifier en lisant le manuel : http://www.php.net/manual/en/function.imagestring.php

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2004
    Messages
    158
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2004
    Messages : 158
    Par défaut
    Bonjour Shikiryu,

    Merci pour ta réponse ! En fait si j'ai bien mes variables mais dans mon autre fichier...

    En fait j'ai la hierarchisation suivante :
    Repertoire "Class/gd-gradient-fill.php"

    et dans mon repertoire principal j'ai bien mes variables :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    require_once('class/gd-gradient-fill.php');
     
    //create image from scratch with gradient
    	$width = 500;
    	$height = 200;
    	$direction = vertical;
    	$startcolor = "#FF0000";
    	$endcolor = "#cccccc";
    	$step = 0;
    	$image = new gd_gradient_fill($width,$height,$direction,$startcolor,$endcolor,$step);
    Mais ça ne fonctionne pas... j'ai aussi essayé de mettre directement ta ligne de code (avec la bonne font que j'ai sur mon serveur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    $font = "../fonts/Harabara.ttf";
    $textcolor = imagecolorallocate($this->image, 0, 0, 255); // bleu
    imagettftext($this->image, 12, 0, 0, 0, $textcolor , $font ,  "hello world" );
    Je l'ai mis dans le fichier gd-gradient-fill.php juste après :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    		// Fill it
    		$this->fill($this->image,$this->direction,$this->startcolor,$this->endcolor);
    mais ça ne fonctionne pas non plus...

  8. #8
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Il serait malin etant donné que tu n'y arrives pas, de faire un test dans un fichier simple et sans utiliser de variables.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  9. #9
    Membre émérite

    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2011
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 411
    Par défaut
    Citation Envoyé par rigolman Voir le message
    Merci pour ta réponse ! En fait si j'ai bien mes variables mais dans mon autre fichier...
    J'ai l'impression que quelqu'un ne connait pas vraiment pas programmation POO...

    Tu ne peux pas faire appel à des variables d'un autre fichier dans un constructeur à moins de :
    • Inclure ce fichier dans ce constructeur (yerk)
    • En faire des variables globales (yerk yerk)
    • Les passer en paramètre (yay)


    Citation Envoyé par rigolman Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $direction = vertical;
    M'étonne que tu n'aies pas eu de plantage ici... $direction = 'vertical'; ?

    Citation Envoyé par rigolman Voir le message
    mais ça ne fonctionne pas non plus...
    Un commentaire un peu plus constructif serait le bienvenue... Une erreur ? un message ? Qu'est ce qui apparait ?

Discussions similaires

  1. [HTML] HTML: Superposer du texte sur une image
    Par claralavraie dans le forum Balisage (X)HTML et validation W3C
    Réponses: 7
    Dernier message: 09/02/2006, 13h44
  2. [HTML][DREAMWEAVER] Texte sur une image
    Par Nicos77 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 12/10/2005, 09h43
  3. Centrer un texte sur une image créée dynamiquement
    Par rigolman dans le forum Langage
    Réponses: 7
    Dernier message: 11/10/2005, 17h22
  4. Positionnement de texte sur une image
    Par inddzen dans le forum Windows
    Réponses: 2
    Dernier message: 08/08/2005, 12h22
  5. [HTML]Peut-on écrire un texte sur une image ?
    Par flogreg dans le forum Balisage (X)HTML et validation W3C
    Réponses: 4
    Dernier message: 28/02/2005, 17h24

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