Results 1 to 5 of 5

Thread: Simple Quetion, Read top line of text file... HELP [nooooob]

  1. #1

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    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.
    Zeegnahtuer?

  2. #2
    Addicted Member Phenix's Avatar
    Join Date
    Sep 2002
    Location
    Near A Cube
    Posts
    228

    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

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    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 ?
    Zeegnahtuer?

  5. #5

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: Simple Quetion, Read top line of text file... HELP [nooooob]

    roflcopter *bump* type thing ?
    Zeegnahtuer?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width