Hi, I am trying to create a thumbnail of an image and show it on the browser without creating an actual file of the thumbnail...rather show it through a function. I am doing it in a smarty library using site..(i dont know if thats the problem)
I got a profile.tpl, a profile.php and a functions.php where i have the function.
In the profile.php i have the function calling . ex:
$pic = createThumb("1.jpg"); and at the end
$smarty->assign('pic', $pic);
In the profile.tpl i have:
{$pic} to show the picture
and in the function.php
function createThumb($source) {
$thumb_size = 25;
$size = getimagesize($source);
$width = $size[0];
$height = $size[1];
$y = NULL;
$x = NULL;
if($width> $height) {
$x = ceil(($width - $height) / 2 );
$width = $height;
} elseif($height> $width) {
$y = ceil(($height - $width) / 2);
$height = $width;
}
$new_im = ImageCreatetruecolor($thumb_size,$thumb_size);
$im = imagecreatefromjpeg($source);
imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height);
header('Content-type: image/jpeg');
imagejpeg($new_im,"",100);
imagedestroy($im);
}
The problem is that when i check the page on the browser i get alot of garbage on the top like :
�����JFIF���������>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ���C� $.' ",#(7),01444'9=82<.342���C 2!!22222222222222222222222222222222222222222222222222�����"�������������� �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������
and no image of course where it should be.
I realise its because its not sending the header('Content-type: image/jpeg'); to the browser first so it displays the image.
Can anyone help me out here ? What am i doing wrong ?
Thanks
....EDIT.....
Btw this image is just a part of an html page...I dont want to just show this image on the page....but inside a <td> so i cant just put {header('Content-type: image/jpeg');} at the top of the page....cause it will just show the image and nothing else.
I am doing all this because i dont want to take extra space on a temp folder by making thumb images.
If there is a way to delete the images after they are shown to the user then i can go with that solution also...I can make it work by making tmp images, i just dont know how to delete them after.