Tech Reviews, Guides, Articles, and Forums for PC Hardware, Modding, and Gaming Enthusiasts
Fury-Tech Forums

Go Back   Fury-Tech Forums > Software Forums > Programming and Coding

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-13-2004, 10:28 AM
Cipher
Cipher
 
Join Date: Apr 2004
Location: EarthPlanet
Posts: 2
Rep Power: 0
Nasimov is on a distinguished road
Default PHP image.

Hello!

I want to load text from a .txt file on the web and put it on to an image. How can I do that in php?

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-13-2004, 11:07 AM
freshtokyo's Avatar
Great Diviner
Great Diviner
 
Join Date: Nov 2003
Location: In Maine
Posts: 1,638
Rep Power: 7
freshtokyo is on a distinguished road
Send a message via AIM to freshtokyo
Default

you want to put the text over an image?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-13-2004, 04:27 PM
Tekime's Avatar
Administrator
Great Diviner
 
Join Date: Aug 2002
Location: Maine
Posts: 5,248
Rep Power: 10
Tekime is on a distinguished road
Send a message via AIM to Tekime Send a message via MSN to Tekime Send a message via Yahoo to Tekime
Default

If you want to load a text file and create an image using that text it isn't too tough. If you want to take that text and overlay an existing image, I'm not sure.

But if you just want to generate an image that has the text in whatever font, it's pretty straight-forward.

You can try somethign like the following to generate the image. If you want the content from a file just use fopen to open the file, then read from the pointer into a variable and use that variable as your text.

Here's a little sample code of something I have:

Code:
<?

   header("Content-type: image/jpeg");


    $s = 20;
    $text = "";
    
    if($_GET['s']) $s = addslashes($_GET['s']);
    if($_GET['text']) $text = addslashes($_GET['text']);
  
  
  if(!isset($s)) $s=11;
  $size = imagettfbbox($s,0,"/path/to/fonts/BROOKLYN.TTF",$text);
  $dx = abs($size[2]-$size[0]);
  $dy = abs($size[5]-$size[3]);
  $xpad=9;
  $ypad=9;
  $im = imagecreate($dx+$xpad,$dy+$ypad);
  $blue = ImageColorAllocate($im, 0x2c,0x6D,0xAF);
  $black = ImageColorAllocate($im, 0,0,0);
  $white = ImageColorAllocate($im, 255,255,255);
  ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black);
  ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$white);
  ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, "/path/to/fonts/BROOKLYN.TTF", $text);
  ImageTTFText($im, $s, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $white, "/path/to/fonts/BROOKLYN.TTF", $text);
   imagejpeg($im, "", 75);
  ImageDestroy($im);
?>
You can test it here:

http://fury-tech.com/tools/image.php?s=24&text=Hello

It accepts two _GET arguments, size and text. Size specifies the font size, text specifies the text to print.

Just an example, but it lays it out pretty simple. Good luck!
__________________
ABIT NF8 | Athlon 64 2800+ | 1GB Corsair XMS PC-3200 | MSI GeForce 6600GT

My blog, business, Twitter, ryze, LinkedIn, Digg, Facebook
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Currently Viewing
Go Back   Fury-Tech Forums > Software Forums > Programming and Coding




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
A Better Image Rotator Tekime General Software 0 08-18-2004 03:32 AM
Smarter Image Hotlinking Prevention Tekime General Software 0 08-18-2004 03:32 AM
A Better Image Rotator Tekime Graphics, Web Design, CSS & Scripting 0 08-15-2004 01:15 AM
Smarter Image Hotlinking Prevention Tekime Graphics, Web Design, CSS & Scripting 0 08-15-2004 01:15 AM
Free Image Hosting @ Fury-Tech.com Tekime Jibber Jabber 14 03-25-2003 01:25 PM


All times are GMT -5. The time now is 10:56 PM.


PHP Scripts
BidVerve Directory
PageRank Script
SEO Scripts
37 SEO Scripts
List Cleaner Script
Keyword Cleaner
Directory Script
Directory Script

Directories
BidVerve Directory
BidVerve Directory
Nerve Directories
Nerve Directories
Directory Grow
Directory Grow

Our Supporters
entertainment sites
online casino

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0 ©2007, Crawlability, Inc.