image display problem!!
Posted: Sun Sep 07, 2008 10:12 am
i have a link : http://www.test.com/thumb.php?img=wallp ... =800&h=600
when a user click on that link, that link should open to a new window and display the image but instead of displaying the image, it automatically downloads the image..
So how to display the image in new window??
could you please help me out??
below is the code for thumb.php
when a user click on that link, that link should open to a new window and display the image but instead of displaying the image, it automatically downloads the image..
So how to display the image in new window??
could you please help me out??
below is the code for thumb.php
Code: Select all
<?
function thumb_on_fly($img,$h=null,$w=null,$max=80)
{
if(file_exists($img))
{
if( isset($h) && isset($w) )
{
$s = getimagesize($img);
$sx = $s[0];
$sy = $s[1];
$source = imagecreatefromjpeg($img);
$target = imagecreatetruecolor($w, $h);
$copy = imagecopyresampled($target, $source, 0, 0, 0, 0, $w, $h, $sx, $sy);
$image = imagejpeg($target);
imagedestroy($target);
return $image;
}
else // scale automatically until < $max while keeping aspect ratios
{
$s = getimagesize($img);
$sx = $s[0];
$sy = $s[1];
if($sx > $sy/2)
{
$nw=$max;
$nh=($sy/$sx)*$nw;
}
else
{
$nh=$max*2;
$nw=($sx/$sy)*$nh;
}
$source = imagecreatefromjpeg($img);
$target = imagecreatetruecolor($nw, $nh);
$copy = imagecopyresampled($target, $source, 0, 0, 0, 0, $nw, $nh, $sx, $sy);
$image = imagejpeg($target);
imagedestroy($target);
return $image;
}
}
}
if ( isset($_GET['img']) && !isset($_GET['h']) && !isset($_GET['w']) && !isset($_GET['max']) )
{
header("content-type: image/jpg");
thumb_on_fly($_GET['img']);
}
elseif ( isset($_GET['img']) && isset($_GET['h']) && isset($_GET['w']) && !isset($_GET['max']) )
{
header("content-type: image/jpg");
thumb_on_fly($_GET['img'],$_GET['h'],$_GET['w']);
}
elseif ( isset($_GET['img']) && !isset($_GET['h']) && !isset($_GET['w']) && isset($_GET['max']) )
{
header("content-type: image/jpg");
thumb_on_fly($_GET['img'],null,null,$_GET['max']);
}
?>