GD Help(Text color)

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
dcahrakos
Forum Newbie
Posts: 11
Joined: Mon Sep 26, 2005 6:52 pm

GD Help(Text color)

Post by dcahrakos »

I have a basic script, which lets you just put txt=something here and it prints that out in the image, well, im trying to take it a little further, and im trying to get it to have gradient font, I havent the slightest clue on how I could do that...I can do single colors, but im not sure how I could get a gradient, Can anyone help me here?

here is my code:

Code: Select all

<?php

header("Content-type: image/png");
	$string = $_GET['txt'];
	
	$length=strlen($string) * 8.5;
	$im = imagecreate($length, 17);
 //Set the BG color.
	$background_color = imagecolorallocate($im, 0, 0, 0);
 //Now the Text Color.
	$text_color = imagecolorallocate($im, 100, 100, 255);
 //The image string, which is the txt, from the URL.
	imagestring($im, 3, 4, 0,  $string, $text_color);
 //transparency stuff
	ImageColorTransparent($im,0);
 //Output the Image
	imagepng($im);
//Destroy it, freeing memory.
	imagedestroy($im);
?>
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

If someone does not answer you, check back tomorrow sometime and I will have something for you. I have not seen anything that does text2gradient() so it sounded like it was neat thing to create! I got most of it done but I am off to the movies now so I will not have time to finish it right now. I was going to make it really simple but then I was thinking that it would be better to just make function that you pass the text to and also the info telling the function what you want done to it (gradientize) and the function will return the image resource so you can lay out the text on another image resource or you just call imagegif(), imagepng(), imagejpeg() and display it or put it in a file!

This is the array you will pass to the function text2gradient()

/*
* text array
*
* str = the string to gradientize (str)
* type = the gd function to use ( 0 = imagettftext(), 1 = imagestring() ) (int)
* size = the font size to use ( font size = 10 ) (int)
* gsc = the RGB starting color for the gradient array ( R, G, B ) (array), (int) values
* gec = the RGB ending color for the gradient array ( R, G, B ) (array), (int) values
* dir = the gradient direction ( 0 = left to right (horizontal), 1 = top to bottom (vertical) ) (int)
* path = the path and name to your font file ( if text array type = 0, else '' ) (str)
*
*/

:: QUICK NOTE::

To make the colors reverse [lite to dark, dark to lite], (gse, gec) just reverse the two arrays!

yj
dcahrakos
Forum Newbie
Posts: 11
Joined: Mon Sep 26, 2005 6:52 pm

Post by dcahrakos »

Alright, cool, ill check back tomorrow, thanks :)
Post Reply