Page 1 of 1

ImageTTFText Question

Posted: Fri Apr 09, 2004 9:45 am
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.

Posted: Fri Apr 09, 2004 3:23 pm
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..