[Php] Image return /print

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by beandab, Jun 6, 2008.

  1. beandab

    beandab New Member

    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Hey all,
    well i am also a newbie :)

    i saw this on many sites:
    <img src="somephp.php?blabla" width="100">

    how can i make that to?

    i want to reffer to a php file that returns or prints a jpg image and in the
    <img src=must be a php url>

    Best regards M
     
  2. woiwky

    woiwky New Member

    Messages:
    390
    Likes Received:
    0
    Trophy Points:
    0
    You need to use the gd library image functions to accomplish that. You also have to be sure to specify the content-type header before outputting the image data.

    Here's an example from php.net:

    PHP:
    <?php
    header 
    ("Content-type: image/png");
    $im = @imagecreatetruecolor(12020)
          or die(
    "Cannot Initialize new GD image stream");
    $text_color imagecolorallocate($im2331491);
    imagestring($im155,  "A Simple Text String"$text_color);
    imagepng($im);
    imagedestroy($im);
    ?>
    This code will generate a 120x20 image with a black background with the text "A Simple Text String" in red, output it in png format, and then free the memory associated with that image.
     
  3. oscetips

    oscetips New Member

    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    0
    adapted from php.net...

    -- image.php --
    <?php
    $filename = "path/to/image/".$_GET['name'].".jpg";
    header('Content-type: image/jpeg');
    header('Content-transfer-encoding: binary');
    header('Content-length: '.filesize($filename));
    readfile($filename);
    ?>

    --your html code--
    <img src="http://forums.x10hosting.com/programming-help/image.php?name=test">
     

Share This Page