I'm using this piece of php code to create and rotate an image. And it works perfectly when i just call the img.php it lying in.
But if i try to include the img.php in anything else, or just include the snippet in another page (on same server) it just shows me a lot of questionmarks instead of an image.
My feeling is that the problem is related to the headers sent, but honestly i have no idea.
Any suggestions how to make this useful so it can be included in another page and still work?
<?php
header("Content-type: image/jpeg");
// option one
// create a 250*77 image
$im = imagecreate(250, 77);
// option two
// creating a image from jpeg
$im = @imagecreatefromjpeg("images/test.jpg")
or die("Cannot Initialize new GD image stream");
// white background and black text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 0);
//create the text
$skrivetekst = date('d.m.Y');
$skrivetekst2 = date('H:i:s');
// write the string at the top left
imagestring($im, 5, 0, 0, $skrivetekst, $textcolor);
imagestring($im, 5, 0, 20, $skrivetekst2, $textcolor);
///Rotate the image
$rotate = imagerotate($im, 90, 0);
// output the image
// Output
imagejpeg($rotate);
ImageDestroy ($rotate);
?>
Regards Troels