Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Adding data to an image file - Can it be done?
Old 06-30-2006, 11:12 AM Adding data to an image file - Can it be done?
Webmaster Talker

Posts: 626
Trades: 0
I have an image file which is rateboard.gif, and I have a database with all my rates in it which is updated on a daily basis.

Now, the file rateboard.gif is just a background and I want to setup a cron job which will automatically take the rates which are saved in my database and input them into the GIF file using the courier font. Then I want to save the new GIF file.

Is this something that can be done using PHP? If so, can anyone point me to a script or tutorial?
jim.thornton is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-30-2006, 11:52 AM Re: Adding data to an image file - Can it be done?
Average Talker

Posts: 16
Location: Seattle, WA
Trades: 0
Yes, you can use the GD library to manipulate images from PHP (more info here http://us2.php.net/image). On most servers it's already installed.
vtechno42 is offline
Reply With Quote
View Public Profile Visit vtechno42's homepage!
 
Old 06-30-2006, 12:00 PM Re: Adding data to an image file - Can it be done?
Average Talker

Posts: 16
Location: Seattle, WA
Trades: 0
Furthermore, some code that seems to be pretty close to what you're looking to do is listed in the comments. (code is here http://us2.php.net/manual/en/ref.image.php#62436)

Modifying this to pull the text you want from a your rates database should be as simple as connecting to the DB, then modifying this line of code ( $text = @$_GET['text']; ) making the $text var point to the output of the database. Hope that helps! =)
vtechno42 is offline
Reply With Quote
View Public Profile Visit vtechno42's homepage!
 
Old 06-30-2006, 03:14 PM Re: Adding data to an image file - Can it be done?
Webmaster Talker

Posts: 626
Trades: 0
Ok... Thanks for the help guys.

I have tried it and I can't figure out why but for some reason the red color is working but the blue and black colors aren't working.

Can anyone see why not?

Code:
header("Content-type: image/gif");
$im    = imagecreatefromgif("http://localhost/images/moneytime_rates.gif");
$red = imagecolorallocate($im, 255, 0, 0);
$black = imagecolorallocate($im, 10, 10 , 10);
$blue = imagecolorallocate($im, 30, 0, 255);

$string = "VARIABLE RATES";
$px    = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 25, $string, $red);
imagegif($im);
imagedestroy($im);
jim.thornton is offline
Reply With Quote
View Public Profile
 
Old 06-30-2006, 03:25 PM Re: Adding data to an image file - Can it be done?
Average Talker

Posts: 16
Location: Seattle, WA
Trades: 0
It's because you have not called these variables in the text display...

PHP Code:
imagestring($im3$px25$string$red$black$blue); 
that should do it.
vtechno42 is offline
Reply With Quote
View Public Profile Visit vtechno42's homepage!
 
Old 06-30-2006, 05:17 PM Re: Adding data to an image file - Can it be done?
Webmaster Talker

Posts: 626
Trades: 0
Ya lost me on that one! but that's okay, I was able to figure it out by using this:

Code:
header("Content-type: image/gif");
$im    = imagecreatefromgif("C:\Documents and Settings\Administrator\desktop\RateBoard copy.gif");
$font = 'arial.ttf';
$bg = imagecolorallocate($im, 255,255,255);
$red = imagecolorallocate($im,255,0,0);
$blue = imagecolorallocate($im, 30,0,255);
$black = imagecolorallocate($im, 0,0,0);

$string = "VARIABLE RATES";
$px    = (imagesx($im) - (imagefontwidth(3)*strlen($string)))/2;
imagettftext($im,9,0, $px, 65,$black,$font,$string);
imagegif($im);
imagedestroy($im);
The problem was that the colors weren't in my pallette for some reason when I saved the background. I added the colors to the pallette and now it works fine.

NEW PROBLEM:

Is it possible to add style to the text that goes in the image... For example in some cases I want to add an underline and in others I want to add bold text. Is this possible? I can't find it anywhere on google. Or in the PHP manual
jim.thornton is offline
Reply With Quote
View Public Profile
 
Old 06-30-2006, 05:51 PM Re: Adding data to an image file - Can it be done?
Average Talker

Posts: 16
Location: Seattle, WA
Trades: 0
Quote:
Originally Posted by zincoxide
NEW PROBLEM:

Is it possible to add style to the text that goes in the image... For example in some cases I want to add an underline and in others I want to add bold text. Is this possible? I can't find it anywhere on google. Or in the PHP manual
That I have no clue about, you may be able to use HTML code, but I've never tried to add style dynamically to an image, it may just output the tags if you use HTML.

Look through PHP.com for info on working with strings, there should be a way to manipulate the text prior to it being output in the image.
vtechno42 is offline
Reply With Quote
View Public Profile Visit vtechno42's homepage!
 
Old 07-01-2006, 11:04 PM Re: Adding data to an image file - Can it be done?
Webmaster Talker

Posts: 626
Trades: 0
I have decided that I can just draw a line underneath the text... Also for bold I can just change to the bold font.

Thanks again for the help!
jim.thornton is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Adding data to an image file - Can it be done?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.38122 seconds with 12 queries