Jump to content

GD 2 different text colours


Chris92

Recommended Posts

Hi, I'm making a soort of label that has the day number and month on it with GD, one problem is I want to make the day number green which works fine but when I try setting the month to grey it just stays white.

Here's the current code I'm using:

<?php
header("Content-type: image/Gif");

$im = imagecreatefromgif("back.gif");
$green = imagecolorallocate($back, 117, 144, 48);
$grey = imagecolorallocate($back, 85, 85, 85);
imagettftext($im, 18, 0, 11, 25, $green, 'CALIBRI.TTF', "{$_GET['q']}");
imagettftext($im, 14, 0, 10, 43, $grey, 'CALIBRI.TTF', "{$_GET['w']}");

imagegif($im);
imagedestroy($im);
?>

 

http://chrishmmens.freehostia.com/images/label.php?q=10&w=FEB

 

I treid switching the green and grey variables around which caused the month to come up in grey but the day came up in white.

I also treid setting the grey variable after the day number was set onto the images which stopped the image from showing up all together.

 

Thanks for any help, Chris.

 

 

Link to comment
https://forums.phpfreaks.com/topic/90393-gd-2-different-text-colours/
Share on other sites

Solved! I simply put the colorallocate funtion inside of the funtion to set the string:

<?php
header("Content-type: image/Gif");

$im = imagecreatefromgif("back.gif");

imagettftext($im, 18, 0, 11, 25, imagecolorallocate($im, 117, 144, 48), 'CALIBRI.TTF', "{$_GET['q']}");
imagettftext($im, 14, 0, 10, 43, imagecolorallocate($im, 85, 85, 85), 'CALIBRI.TTF', "{$_GET['w']}");

imagegif($im);
imagedestroy($im);
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.