Need help for PHP/Image creator function

Discussion in 'PHP' started by amuthavalli, Jun 30, 2009.

  1. #1
    i want help,

    i want the output for text on the image. that is
    see the code
    <?php
    $str="<b>Hello World</b>";
    $im = imagecreatetruecolor(500, 500);
    $text_color = imagecolorallocate($im, 233, 255, 100);
    imagestring($im, 1, 5, 5,  $str, $text_color);
    header('Content-type: image/jpeg');
    imagejpeg($im);
    imagedestroy($im);
    ?>
    
    Code (markup):
    i got the output is <b>Hello World</b>

    but, i need the output is Hello World
    on the image

    please any one have idea?
     
    amuthavalli, Jun 30, 2009 IP
  2. amuthavalli

    amuthavalli Peon

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Any body idea...
     
    amuthavalli, Jun 30, 2009 IP
  3. hip_hop_x

    hip_hop_x Active Member

    Messages:
    522
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #3
    remove the <b> and </b>, and increase the font size
     
    hip_hop_x, Jun 30, 2009 IP
  4. amuthavalli

    amuthavalli Peon

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    no.


    this is file1.php file

    
    <?php
    echo'
    <script type="text/javascript">
    <!--
    function popup() {
        alert("Hello World")
    }
    //-->
    </script>';
    
    
    
    echo '<body>
    <input type="button" onclick="popup()" value="popup">
    </body>';
    ?>
    PHP:
    display output on the image
    
    <?php
    $file = file_get_contents('./file1.php', public_html);
    $im = imagecreatetruecolor(500, 500);
    $text_color = imagecolorallocate($im, 233, 255, 100);
    imagestring($im, 1, 5, 5,  $file, $text_color);
    
    // Set the content type header - in this case image/jpeg
    header('Content-type: image/jpeg');
    
    // Output the image
    imagejpeg($im);
    
    // Free up memory
    imagedestroy($im);
    ?>
    
    PHP:
    it shows errors.

    i'll use verification in script,
    when i click the button it verify and display the hello world on image at second php file.
    so my output is Hello World on the image

    how can i get?

    pls give any idea........
     
    amuthavalli, Jun 30, 2009 IP
  5. daringtakers

    daringtakers Well-Known Member

    Messages:
    808
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    110
    #5
    daringtakers, Jun 30, 2009 IP
  6. JDevereux

    JDevereux Peon

    Messages:
    50
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This seems to work OK. You can change the value of "$n<=" to change the font weight. 2 for semi-bold; 8 for really bold.

    // Create a new image instance 
    $im = imagecreatetruecolor(200, 200);
    
    // Make the background white
    imagefilledrectangle($im, 0, 0, 199, 199, 0xFFFFFF);
    
    $textcolor = imagecolorallocate($im, 0, 0, 0);
    
    imagestring($im, 5, 100, 80, 'Normal Text', $textcolor);
    
    $x_cord = 100;
    $y_cord = 100;
    
    $text = 'Bold Text';
    
    $_x = array(1, 0, 1, 0, -1, -1, 1, 0, -1); 
    $_y = array(0, -1, -1, 0, 0, -1, 1, 1, 1); 
    
    // Change value of "$n<=" to change font-weight
       for($n=0;$n<=8;$n++) 
       { 
          imagestring($im, 8, $x_cord+$_x[$n], $y_cord+$_y[$n], $text, $textcolor);
       } 
    
    // Output the image to browser
    header('Content-type: image/gif');
    
    imagegif($im);
    imagedestroy($im);
    PHP:
     
    JDevereux, Jun 30, 2009 IP