Reputation: 398
Am working with an small php project . in creating an text generating image. took some sample codes and tired.
<?php
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
header('Content-Type: image/jpeg');
imagejpeg($im);
imagedestroy($im);
?>
i made some changes and it works good . when i tried to insert this php file in other html file using it results broken image. how can i solve this why it happens.
Upvotes: 0
Views: 142
Reputation: 782498
You can't have the same page being both HTML and an image. The way you do what you want is by having the HTML file contain an IMG
tag that references this script.
<img src="yourscript.php">
Upvotes: 0
Reputation: 8236
An HTML file cannot have multiple header sections. Once you have rendered content on the page the call to header()
will generate an error.
Upvotes: 0
Reputation: 47985
Please make sure that you don't have any whitespace before your <?php
statment. In your example above there are 4 spaced before the <?php
. Note that this also is important for empty lines.
Upvotes: 1