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
https://forums.phpfreaks.com/topic/74536-imagecopyresampled-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.