Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    GD output to file?

    Hi,

    I know how to use GD to create images on the fly (such as nowplaying gfx ). My question is: is it posible to have the image outputted to a file stored on the server (eg /imgs/on-the-fly/NUM.png where NUM is a number) rather than inserted into the page using <img src="mygdscript.php">?

    I would use this to create headers in a certain font. A PHP script checks if the graphic already exists (fairly simple I assume if a common naming system is employed) and if not commissions the GD script to output the created image to a file, so in future it is already there - no need to make it for every visitor.

    Is this possible and if so, how?
    skinme.net / v2.php (design nearly completed)

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    British Columbia
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have not worked with image in PHP, but I have seen how they work. You might be able to use output buffering to capture the output and then save it as a file.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    depending upon which format you are parsing the image as, the create as file option resides within using extra parameters in the ImageFormat() call.

    eg

    ImagePNG($image_file); => output to browser
    ImagePNG($image_file,'images/image.png'); => output to file as named.

    With jpegs there is a third parameter for compression --

    ImageJPG($image_file,'',85); => to browser at 85% quality.

    Have a look on php.net for the exact format you are outputting in.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #4
    New Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot, will experiment with that later tonight. First got a little HDD to put in my bro's PC. Wish me luck!
    skinme.net / v2.php (design nearly completed)

  • #5
    New Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Allright I've got it outputing to a file. However, I am worried that the folder to which it outputs MUST be 777 (allow all read,write,execute) as this leaves this folder vulnerable to writing or deleting from outside. Is this preventable?

    I know also have a script checking whether a image is already created or not. My problem now is if it already exists passing it back to the original <img src="checkpage.php?text=hello world">. I'm getting red X's. Here's my code so far:

    PHP Code:
    <?php 

    $imgstore 
    "imgstore/";

    if (!
    $text) {
        die(); 
    // die if no text specified, duh
    }

    if (!
    $maxwidth) {
        
    $maxwidth="400"// default width if none specified.
    }

    //check if header already exists.

    $filename $imgstore.str_replace(" ","_",$text).".png";

    if (
    file_exists($filename)) {
        
    //exists so pass file back
        
    $imgpointer fopen($filename'r');
        
    $imgcode fread($imgpointer,filesize($imgpointer));
        
    $fclose($imgpointer);
        return 
    $imgcode;
    }
    else {
        echo 
    "bumbum"// don't exist buddy
    }

    ?>
    Don't worry about my immature error messages or comments -- a guy's gotta have fun coding.

    Am I approaching this the right way? If not, how should I handle it?
    skinme.net / v2.php (design nearly completed)

  • #6
    New Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    CODAAh [createOnDemandAndArchive] is done! Yay!

    Basically, it will be used on my site. It will use a destinctive font unlikely to reside on the users system. As a result article headers will have to be created. I'm too lazy to make them. So I wrote this script to do it for me. (Obviously it could be adapted to create different colour / style text imgs)

    If you wanna try it out, the URL is: http://skinme.net/misc/createOnDemand/test.php?text=*PUT A SMALLISH (400px worth) TEXT STRING HERE*. I will be moving it sooner or later, though. (BTW, the white is a transparent dark blueish colour used on my site)

    Thanks for all your help. /me learnt a lot with this script. Most importantly, read what you've written when you get errors before you got changing ALL the code
    skinme.net / v2.php (design nearly completed)


  •  

    Posting Permissions

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