Jump to content

imagecopyresampled() problem


biggerboy

Recommended Posts

I am using the code below to generate my new image, however instead of showing the image it just shows the url that I am using. What is wrong with my syntax?

 

Thanks,

Alex

 

// Lets make sure the id is safe
$id = $_GET['id'];
$id = sql_sant($id);

$query = "SELECT * FROM images WHERE id= '$id'";
$result = mysql_query($query) or die(mysql_error());

if(mysql_num_rows($result) == 0)
{
$errormsg =	'Invalid ID, redirecting you back to homepage<br /> You will be redirected in 5 seconds, if you are not redirected <a href =" . $url . "> click here </a>';
header('Refresh: 5; url= index.php ');
exit();
}
$line = mysql_fetch_array($result, MYSQL_ASSOC);
$filename = $line['realname'];
$filetype = $line['type'];
$getfile = './imgs/' . $filename;

// Lets get the image to fit into our page
$width = 600;
$height = 600;

list($origwidth, $origheight) = getimagesize($getfile);
if ($width && ($width_orig < $origheight)) {
   $width = ($height / $origheight) * $origwidth;
} else {
   $height = ($width / $origwidth) * $origheight;
}
$imagef = imagecreatetruecolor($width,$height);

if ($filetype == 'image/bmp')
{
$thumb = imagecreatefromwbmp($getfile);
}

if ($filetype == 'image/gif')
{
$thumb = imagecreatefromgif($getfile);
}

if ($filetype == 'image/png')
{

$thumb = imagecreatefrompng($getfile);
}

if ($filetype == 'image/jpeg')
{
$thumb = imagecreatefromjpeg($getfile);
}

// ALMOST done  Just put these babies where they need to be
imagecopyresampled($imagef, $thumb, 0, 0, 0, 0, $width, $height, $origwidth, $origheight);

if ($filetype == 'image/wbmp')
{
header('Content-type: image/vnd.wap.wbmp');
imagewbmp($imagef);

}

if ($filetype == 'image/jpeg')
{
header('Content-type: image/jpeg');
imagejpeg($imagef);

}

if ($filetype == 'image/png')
{
header('Content-type: image/png');
imagepng($imagef);

}

if ($filetype == 'image/gif')
{
header('Content-type: image/gif');
imagegif($imagef);

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.