ImageTTFText Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JohnDigweed
Forum Newbie
Posts: 18
Joined: Sun Mar 28, 2004 6:24 pm
Location: root/user/hell

ImageTTFText Question

Post by JohnDigweed »

Hi,

This is the basic example of ImageTTFTEXT

Code: Select all

<?php
  header("Content-type: image/jpeg");
  $im = imagecreate(400, 30);
  $white = imagecolorallocate($im, 255, 255, 255);
  $red = imagecolorallocate($im, 150, 25, 25);
  
  // Replace path by your own font path
  imagettftext($im, 20, 0, 10, 20, $red, "/path/arial.ttf",
  "Testing... Omega: &#937;");
  imagejpeg($im);
  imagedestroy($im);
?>
I added the variable $color, and I put that into the $red variable.

Code: Select all

<?php
  header("Content-type: image/jpeg");
  $im = imagecreate(400, 30);
  $color = "150, 25, 25";
  $white = imagecolorallocate($im, 255, 255, 255);
  $red = imagecolorallocate($im, $color);
  
  // Replace path by your own font path
  imagettftext($im, 20, 0, 10, 20, $red, "/path/arial.ttf",
  "Testing... Omega: &#937;");
  imagejpeg($im);
  imagedestroy($im);
?>
But for some reason, when i use the $color variable, imagecolorallocate cant read the color value. It just displays the text color as black when it should be red.

Any way to do this?

Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

imagecolorallocate requires 4 arguments. with

Code: Select all

imagecolorallocate($im, $color)
you are passing 2 arguments. the second, being a string, which it doesn't want. You could use eval() for that.. or break the numbers apart..
Post Reply