|
-
Mar 1st, 2005, 11:12 AM
#1
Thread Starter
Frenzied Member
Simple Quetion, Read top line of text file... HELP [nooooob]
Ok, all i want this to do is read the top line of a file called Song.txt (which resides in the same directory)
i want it to be the text attribute of the coding, i hope you understand what i mean.
This should be really simple, but i am a total noobie to this, and i am using the GDI library to draw an image.
heres my code, i hope you can edit it to work. thanks.
Code:
<?php
// You need this to make sure that browsers read this as an image
header("Content-type: image/png");
$font_size = 14;
// Text to output
$text = $_GET['text'];
// Location of the base graphic
$base = $_GET['image'];
// Colors in RGB format for the TEXT
// This is NOT Hex (#) format
// To get the RGB values for a color, use something like photoshop
$r = "255";
$g = "255";
$b = "255";
// Code to create the actual image
$im = imagecreatefrompng($base);
$color = imagecolorallocate($im, $r, $g, $b);
// X-Position of Text [directly in middle with this code]
// Change the 6 to a different value based on the font you pick later on
$px = (imagesx($im) - 15 * strlen($text)) / 2;
// Y-Position of Text
// Change this based on the X-Position and Font if needed
$py = '18';
// Font (1 = small/pixel, 2 = similar to verdana, 3 = large/bold, etc)
$font = $_GET['font'];
imagettftext($im, $font_size, 0, $px, 30, $black, $font, $text);
imagepng($im);
imagedestroy($im);
?>
thankyou.
-
Mar 1st, 2005, 03:48 PM
#2
Addicted Member
Re: Simple Quetion, Read top line of text file... HELP [nooooob]
PHP Code:
$lines = file('Song.txt');
// $lines[0] is the top line of a file called Song.txt
Can also be a URL
http://www.php.net/manual/en/function.file.php
I'm probably missing what you mean since you mentioned graphics.
Actually, I think you are trying to extract text from a graphics file, but won't it just be pixels as the input? I'm doing something similar so I'd like to know the solution you come up with.
Circa 1995
Engineer - I think we should put our website address on our paper catalogs.
Vice President - Don't get too excited about this internet thing.
I am sorry, but the Oracle was mistaken. You cannot help us.
-Matrix video game
I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones. ... and it probably never will support anything other than AT-harddisks, as that's all I have :-(.
-Linus
Question. Do you know that the character "?" means I'm asking a question? Question. Do you know that spoken inflection also provides the same cue? So please don't say, "Question" before you ask your question. Believe me I'll know.
That said, I would have said this first if it had to precede what I'm telling you now. Having said that, what I'm telling you now is the same thing I just said about the annoying phrases "That said" and "Having said that".
Are you threatening me, Master Jedi?
-Chancellor Palpatine
-
Mar 1st, 2005, 05:08 PM
#3
Re: Simple Quetion, Read top line of text file... HELP [nooooob]
If the file is only one line in size then Pehnix's method is ideal and easiest. If you have a large file with many lines however, it is better to use the method below as it does not require that the entire file be loaded into memory:
PHP Code:
if ($hwnd = fopen($file, 'rb')) {
$line1 = trim(fgets($hwnd));
fclose($hwnd);
}
Remember that in both examples you should use the rtrim() function to strip the new line characters from the end of the text.
-
Mar 2nd, 2005, 12:51 PM
#4
Thread Starter
Frenzied Member
Re: Simple Quetion, Read top line of text file... HELP [nooooob]
Thanks, the $lines[0] worked very well for me 
I just have one problem, i have php_gd.dll and it works fine, but whats the advantage of php_gd2.dll ???
I also have an issue with the PNG image being created, its really bad, and the colours are rubbish, is there anyway to produce higher quality images ?
-
Mar 5th, 2005, 07:31 AM
#5
Thread Starter
Frenzied Member
Re: Simple Quetion, Read top line of text file... HELP [nooooob]
roflcopter *bump* type thing ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|