tags:

views:

55

answers:

1
<?php

header ("Content-type: image/pjpeg");
$string = "manujagadeesh!!!";                                             
$font  =8;
$width  = ImageFontWidth($font)* strlen($string) ;
$height = ImageFontHeight($font) ;

$im = ImageCreateFromjpeg("sachin.jpg");
$x=100;
$y=200;
$background_color = imagecolorallocate ($im, 255, 255, 255); //white background
$text_color = imagecolorallocate ($im, 0, 0,0);//black text
imagestring ($im, $font, $x, $y,  $string, $text_color);
imagejpeg ($im);
?>

this is the add text to image in php

wen we inclue the my html page the text is not displaying

for eg

<?php

header ("Content-type: image/pjpeg");
$string = "manujagadeesh!!!";                                             
$font  =8;
$width  = ImageFontWidth($font)* strlen($string) ;
$height = ImageFontHeight($font) ;

$im = ImageCreateFromjpeg("sachin.jpg");
$x=100;
$y=200;
$background_color = imagecolorallocate ($im, 255, 255, 255); //white background
$text_color = imagecolorallocate ($im, 0, 0,0);//black text
imagestring ($im, $font, $x, $y,  $string, $text_color);
imagejpeg ($im);
?>

hi welcome

couldn't see the hi wlecome

+2  A: 

You can't output both content of type image/jpeg and text/html from the same PHP script. Move your image generation code to another file eg stringImage.php and use the following code to include it:

<img src="stringImage.php" />
hi welcome

As long as stringImage.php only outputs the image data with the correct content type, and nothing else, you should get your expected result.

richsage
thanks for answering
jagadeeshbalu
@tismon if the answer fixed your issue, mark it as accepted by clicking the big tick to the left
adam