467,880 Members | 1,256 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,880 developers. It's quick & easy.

Font color in jpeg image (nearly) always orange

I am trying to run a basic script that displays an existing jpeg image
and writes some text over it. Sounds simple, but I cannot seem to be
able to colour the font correctly. In the example below it should be
black but it comes out orange. In fact, even if I change the colour to
0, 0, 255 it's orange.

I've read in the PHP documentation (the user contributed notes) that
there are issues with jpeg font colouring. But I've not seen any
details. Can anyone shed light on this for me please?

The example code below is called as a function. The $image variable is
a path to the existing image file and the $ttf variable is a path to a
TrueType font. The $text variable contains a text string.

header("Content-type: image/jpeg");
$base_image = imagecreatefromjpeg($image);
$font = $ttf;
$fontcolor = imagecolorallocate($base_image, 0, 0, 0);
imagettftext($base_image, 18, 0, 10, 100, $fontcolor, $font, $text);
imagejpeg($base_image); imagedestroy($base_image);

Cheers,
Si.

Oct 11 '06 #1
  • viewed: 1652
Share:
1 Reply

sp********@gmail.com wrote:
I am trying to run a basic script that displays an existing jpeg image
and writes some text over it. Sounds simple, but I cannot seem to be
able to colour the font correctly. In the example below it should be
black but it comes out orange. In fact, even if I change the colour to
0, 0, 255 it's orange.

I've read in the PHP documentation (the user contributed notes) that
there are issues with jpeg font colouring. But I've not seen any
details. Can anyone shed light on this for me please?

The example code below is called as a function. The $image variable is
a path to the existing image file and the $ttf variable is a path to a
TrueType font. The $text variable contains a text string.

header("Content-type: image/jpeg");
$base_image = imagecreatefromjpeg($image);
$font = $ttf;
$fontcolor = imagecolorallocate($base_image, 0, 0, 0);
imagettftext($base_image, 18, 0, 10, 100, $fontcolor, $font, $text);
imagejpeg($base_image); imagedestroy($base_image);

Cheers,
Si.
In case anyone with similar problems reads this thread I should point
out that I now believe the failure of the above script to be due to a
bug in an earlier-than-current version of PHP/GD. I am using PHP 4.4,
GD 2.0.26.

It seems that I'm not the only one to get a yellow/orange font (or
nothing, depending on what you set the font colour to) when using
imagettftext and imagecreatefromjpeg (or imagecreatetruecolor). I've
done a work-around involving merging images, but it's not perfect. I
guess the real answer is to upgrade.

Cheers,
Si.

Oct 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Fabian Rossbacher | last post: by
131 posts views Thread by Peter Foti | last post: by
25 posts views Thread by Neal | last post: by
2 posts views Thread by ZUP_DUDE | last post: by
5 posts views Thread by localhost | last post: by
7 posts views Thread by Scott Schluer | last post: by
6 posts views Thread by ryan.mclean | last post: by
1 post views Thread by Joe Cool | last post: by
3 posts views Thread by J(ohn|ane) Doe | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.