+ Reply to Thread
Results 1 to 5 of 5

Thread: php imagecreate

  1. #1
    Join Date
    Nov 2007
    Location
    Tavira - Algarve - Portugal
    Posts
    25

    Exclamation php imagecreate

    hello,
    I started yesterday with bluehost, and I try work with image. I get a script from php.net, and I start with the resource "imagecreate" (http://pt2.php.net/manual/en/function.imagecreate.php).
    I try make a image with this code:
    ---------------------
    ---------------------
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <?php
    header("Content-type: image/png");
    $im = @imagecreate(110, 20)
    or die("Cannot Initialize new GD image stream");
    $background_color = imagecolorallocate($im, 0, 0, 0);
    $text_color = imagecolorallocate($im, 233, 14, 91);
    imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
    imagepng($im);
    imagedestroy($im);
    ?>
    </body>
    </html>
    --------------------------
    --------------------------
    But in the browser not appear the image, just appear text:
    ---------------------
    ---------------------
    Warning: Cannot modify header information - headers already sent by (output started at /home/gloradin/public_html/fotos/index5.php:9) in /home/gloradin/public_html/fotos/index5.php on line 10
    ‰PNG  IHDRnV,šPLTEé[an÷fIDAT•c` `fxÄÀÃ`Ç ÀçÀä²41ƒ‚€˜Ë–Ý’Àq²@੤;{á0— œi
    -------------------------------
    -------------------------------
    The site for view the exemple is http://fotos.gloradin.com/index5.php.

    Please help me for a good solution.

    The best regards,
    Gloradin
    Attached Images

  2. #2
    Join Date
    Nov 2006
    Location
    Sydney, Australia
    Posts
    4,489

    Default

    You need two files to do this

    File one: image.php contains:

    Code:
    <?php
    header("Content-type: image/png");
    $im = @imagecreate(110, 20)
    or die("Cannot Initialize new GD image stream");
    $background_color = imagecolorallocate($im, 0, 0, 0);
    $text_color = imagecolorallocate($im, 233, 14, 91);
    imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
    imagepng($im);
    imagedestroy($im);
    ?>
    The other file contains:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <img src="image.php" />
    </body>
    </html>

  3. #3
    Join Date
    Nov 2007
    Location
    Tavira - Algarve - Portugal
    Posts
    25

    Default

    Thank you Stephen,
    I create two files, image.php with the imagecreate php code, and I create index5.php to show the image.
    If you see the result in http://gloradin.com/index5.php, we can see the place of the image, but we don´t see the image. I try change <img src="image.php" /> to <img src="http://www.gloradin.com/image.php" /> and it is the same thing.
    Can you help me again?

    The best regards,
    Gloradin

  4. #4
    Join Date
    Feb 2006
    Location
    Florida, USA
    Posts
    1,345

    Default

    image.php should ONLY contain this

    PHP Code:
    <?php
    header
    ("Content-type: image/png");
    $im = @imagecreate(11020)
    or die(
    "Cannot Initialize new GD image stream");
    $background_color imagecolorallocate($im000);
    $text_color imagecolorallocate($im2331491);
    imagestring($im155"A Simple Text String"$text_color);
    imagepng($im);
    imagedestroy($im);
    ?>

  5. #5
    Join Date
    Nov 2007
    Location
    Tavira - Algarve - Portugal
    Posts
    25

    Smile

    hello,
    that's perfect now!
    many thanks to stephen and to basil for this big help.

    the best regards
    gloradin

+ Reply to Thread

Posting Permissions

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