textfarbe ändern

  • Themenstarter Themenstarter fercules
  • Beginndatum Beginndatum
F

fercules

ich bins mal wieder mit meinem image manipulation script. diesmal will ich die farbe des textes ändern, aber es funktioniert nicht:

FF0000 sollte eigentlich ein strahlendes rot sein, aber der text wird immer wieder schwarz *würg*


<?


/*
Pull in all the requirements
*/


class img_add_txt{



function img_add_txt($config){

// header
//header("Content-Type: image/gif");
$this->func_header($config['image_type']);

// set up image
$im = ImageCreateFromPNG($config['image_loc']);

// Set up text colors
$text_colors=explode(" ", $config['text_colors']);
$text_color = ImageColorAllocate($im, $text_colors['0'], $text_colors['1'], $text_colors['2']);

// get font dimensiona
$font_height = ImageFontHeight(3);
$font_width = ImageFontWidth(3);

// get image dimensiona
$image_height = ImageSY($im);
$image_width = ImageSX($im);

// get string length
$length = $font_width * strlen($config['text']);

// set the x, y cords of where the text will be placed
if(empty($config['x_pos'])){
// calculate start coordinates for string
$image_center_x = ($image_width/2)-($length/2);
}else{
$image_center_x = $config['x_pos'];
}
if(empty($config['y_pos'])){
// calculate start coordinates for string
$image_center_y = ($image_height/2)-($font_height/2);
}else{
$image_center_y = $config['y_pos'];
}

// write string
imagettftext($im, 12, 0, $image_center_x, $image_center_y, $text_color, $config['schriftart'], $config['text']);

// output to browser
$this->output_image($config['image_type'], $im);

}// End img_add_txt


/*
Output the correct header based
on file type
*/
function func_header($var){

switch($var){
case "PNG":
header("Content-Type: image/png");
break;

case "GIF":
header("Content-Type: image/gif");
break;

case "JPEG":
header("Content-Type: image/jpeg");
break;
}

}// End func_header


/*
Output the correct image type
based on type
*/
function output_image($var, $pointer){

switch($var){
case "PNG":
ImagePNG($pointer);
break;

case "GIF":
ImageGIF($pointer);
break;

case "JPEG":
ImageJPEG($pointer);
break;
}

} // End out output image

} // End of class


/*
coupon image
*/
$config=array(
"schriftart" => "fonts/$schriftartf",
"text" => "$schriftzug",
"text_colors" => "FF 00 00", // RGB Seperated by spaces
"image_loc" => "shirts/gross/$shirt.png",
"image_type" => "PNG", // PNG and GIF Supported
// Optional arguments; default is center area on image
"x_pos" => "105",
"y_pos" => "90",

);

$graphic=new img_add_txt($config);
?>


any ideas warums nicht klappt?

grüße
fercules
 
Das, was du dem Script als Farbe übergibst sind Hexadezimal-Werte, keine RGB-Farbangaben! Wenn du einen RGB-Wert angeben willst, dann müssen das drei Zahlen im Bereich von 0 bis 255 sein.

Beispiele:
Schwarz
Code:
"text_colors" => "0 0 0", // RGB Seperated by spaces
Weiß
Code:
"text_colors" => "255 255 255", // RGB Seperated by spaces
Blau
Code:
"text_colors" => "0 0 255", // RGB Seperated by spaces
Grün
Code:
"text_colors" => "0 255 0", // RGB Seperated by spaces
Gelb
Code:
"text_colors" => "255 255 0", // RGB Seperated by spaces
Rot
Code:
"text_colors" => "255 0 0", // RGB Seperated by spaces
usw.
Ich hoffe, geholfen zu haben....
 
Zuletzt bearbeitet:
Kann sein dass ich mich täusche aber ich fine eure Lösungen recht umständlcih. Mann kann doch auch die Farbwerte als Variable übergeben.
 
danke :)

natürlich, stimmt. vom ganzen html gedudel bin ich die hexadezimal geschichten derart gewohnt, dass ich auf RGB gar nicht gekommen bin. hexadezimale angaben sind ja auch die regel.... vielen dank jedenfalls

grüße
stephan
 
Zurück