Working with image

Discussion in 'PHP' started by JEET, May 23, 2006.

  1. #1
    Hi,
    I saw the following in the code of a hit counter.
    <img src="http://domain.com/count.php?id=1&type=2">

    I think they are calling a php script in a Image tag. Can that be done?
    If yes, how will I read the variables "id" and "type"?
    Then show a picture...

    It's confusing. Can you please help me here?
    Thank you
    jeet
     
    JEET, May 23, 2006 IP
  2. themole

    themole Peon

    Messages:
    82
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Those are GET variables, so you would access them by $_GET['var_name'].

    $id = $_GET['id'];
    $type = $_GET['type'];

    Making images is pretty simple or pretty challenging depending on what you're doing. Here's a very basic example:

    
    <?php //make sure "<?php" is the [B]first line[/B]. Any whitespace or characters before it will break the script
    
    header('Content-type: Image/png');
    
    $im = imagecreate('200', '200'); //creates a 200 x 200 image
    
    //The first color you define will fill the image. In this case white is fine. Use imagefill() otherwise
    $white = imagecolorallocate($im, 255, 255, 255); 
    $red = ImageColorAllocate ($im, 192, 0, 0);
    $blue = imagecolorallocate($im, 0, 0, 255);
    
    ImageString($im, 3, 5, 5, 'This is a test!', $red); //prints a string on your image
    
    imagepng($im); //This actually outputs your image
    imagedestroy($im); //Clears memory and the temp file created (I think)
    
    ?>//No trailing whitespace or characters
    
    Code (markup):
    For more go to PHP.net

    http://us2.php.net/manual/en/ref.image.php

    -the mole
     
    themole, May 23, 2006 IP
  3. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    I cannot express how much amazed I am !!!
    For a moment I think my eyes would have popped out...
    Thanks so much for introducing me to a whole new set of programming.
    Thank you
    Best wishes for you.
    jeet
     
    JEET, May 23, 2006 IP
  4. wmburg

    wmburg Active Member

    Messages:
    300
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #4
    You will need to have the GD library installed to use the image functions mentioned above.

    You can also show an image file with the filesystem functions:

    <?php
    
      header('Content-Type: image/gif');
      $open = @fopen('/path/to/image','r');
      @fpassthru($open);
      @fclose($open);
    
    ?>
    PHP:
     
    wmburg, May 23, 2006 IP
  5. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #5
    Cool alternative...
    So many thanks for your help guys!!!
    Really I am short of words to thank you all who help me here at DP .
    Once again, Thank you for the help!
    Best wishes for you.
    jeet
     
    JEET, May 23, 2006 IP