jagadeeshbalu
jagadeeshbalu

Reputation: 39

not Display text

<?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

Upvotes: 0

Views: 128

Answers (1)

richsage
richsage

Reputation: 27102

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.

Upvotes: 2

Related Questions