Cant display Jpeg
Posted: Thu Feb 18, 2010 2:59 am
I'm trying to load a JPEG, write a caption on it and display it. The code below just displays the image as text:
"????JFIF?? o_M+?emh?E??(?????U????~9|??>???????U?>???o?.???h?????D???/??::E??-V?þ6???w??:%??x?? ??_??1?|?g???????????h?|K?_??_n????????y? C?_ h??H?m|C???*??_????..l??_???O??/?~???/?(????C??<???? ??x???'?/ ?? ~xB?P?w??5t;???w??Q?????? .... "
Where did I go wrong?
"????JFIF?? o_M+?emh?E??(?????U????~9|??>???????U?>???o?.???h?????D???/??::E??-V?þ6???w??:%??x?? ??_??1?|?g???????????h?|K?_??_n????????y? C?_ h??H?m|C???*??_????..l??_???O??/?~???/?(????C??<???? ??x???'?/ ?? ~xB?P?w??5t;???w??Q?????? .... "
Where did I go wrong?
Code: Select all
<?php
$cap = "Hello World!";
caption("bg.jpg", $cap);
function caption($bg_file, $cap)
{
// create image
$img = imagecreatefromjpeg($bg_file);
$red = imagecolorallocate($img, 255,0,0);
// Write the string at the top left
imagestring($img, 5, 10, 10, $cap, $red);
// Output the image
header('Content-Type: image/jpeg');
imagejpeg($img, NULL, 100);
imagedestroy($img);
}
?>