Hiya,
I've created a function to overlay text onto images, but I'm scratching my head to find a way of outputting the image in a way in which it can be utilised within another script or outputted to the screen.
I can call this function from a php script, passing it the image and the text to use, but when the function returns the data - it takes over the page due to the header - all I get as output is the image.
I suspect this is an easy one and just shows a hole in my PHP knowledge - can someone set me straight here?
Thanks!
function makeimage($file, $text) { ob_start(); $x = getimagesize($file); $width = $x[0]; $height = $x[1]; $type = $x[2];
//header('Content-type: $type');
if ($type == 1) {
$im = imagecreatefromgif($file);
} elseif ($type==2) {
$im = imagecreatefromjpeg($file);
} elseif ($type==3) {
$im = imagecreatefrompng($file);
}
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
ob_clean(); //to be sure there are no other strings in the output buffer
imagepng($im);
$string = ob_get_contents();
ob_end_clean();
return $string;
}
I want to create this image, and then have it outputted in such a way as I can display it on screen in amongst all the other output.