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.
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.
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.
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 ?
Re: Simple Quetion, Read top line of text file... HELP [nooooob]
roflcopter *bump* type thing ?