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 4 of 4

Thread: PHP imagecreate

  1. #1
    cxn
    cxn is offline
    New Coder
    Join Date
    Aug 2009
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    PHP imagecreate

    Hi, I'm looking to create a script which posts a random picture from an array.

    Here's the coding:

    PHP Code:
    <?php 
    header
    ("Content-type: image/png"); 
    $avatars[] = "sig/red.png";
    $avatars[] = "sig/yellow.png";
    $avatars[] = "sig/orange.png";
    $avatars[] = "sig/green.png";
    $avatars[] = "sig/blue.png"
    $avatars[] = "sig/pink.png"

    $avatar $avatars[mt_rand(0count($avatars)-1)]; 

    $newavatar imagecreatefrompng($avatar); 
    imagepng($newavatar); 
    imagedestroy($newavatar); 

    ?>
    When I try it in a browser it doesn't work though. It says the image contains errors.

    Any help would be appreciated, thanks!

  • #2
    cxn
    cxn is offline
    New Coder
    Join Date
    Aug 2009
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Found a script that actually works, nevermind :-)

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    If its like you're OP, you don't need imagecreate at all.
    Given that you have the file already, you can pass the necessary header for it ('image/png' in this example), and use a file_get_contents or fread and pump it to the browser as an image.
    GD library has a lot of overhead, if you already have an image and don't need to perform any manipulations to it, keep it simple by just serving it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    cxn (08-28-2009)

  • #4
    cxn
    cxn is offline
    New Coder
    Join Date
    Aug 2009
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you, I didn't know that :-)


  •  

    Posting Permissions

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