Page 1 of 1

Create image thumbnail

Posted: Wed Sep 24, 2008 11:28 am
by akjackson1
For some reason this code just cuts out a little piece of the image in the corner, and doesn't resize it:
"image" is the name of the upload field.

Code: Select all

session_start();
include("config.php");
$image = $_FILES['image']['name'];
$domain = "truth-for-youth.com";
$url = "http://$domain/uploads/$image";
$back = "admin.php?page=main&uploaded";
$folder = "uploads/images";
$by = $_SESSION['username'];
$thumb_path = "uploads/thumbs/$image";
$thumb_img_path = "../uploads/images/thumbs/$image";
$target = "../uploads/images/";
$connection = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to MYSQL');
$db = mysql_select_db("$dbname", $connection) or die("Can't select database.");
$query = "INSERT INTO `images` SET `url`='$url' , `filename`='$image' , `uploaded_by`='$by' , `thumb_path`='$thumb_path' , `folder`='$folder'";
$result = mysql_query($query, $connection) or die("Can't query table.");
mysql_close();
//Save Image
$target = $target . basename( $_FILES['image']['name']) ;
move_uploaded_file($_FILES['image']['tmp_name'], $target);
//Create Thumbnail
if($_FILES['image']['type']=="image/jpeg"){
$im=ImageCreateFromJPEG("../uploads/images/$image");
$width = 150;
$height = ImageSy($im) * ($width/ImageSx($im));
$newimage=imagecreatetruecolor($width,$height);
list($width, $height) = getimagesize("../uploads/images/$image");
imagecopyresampled($newimage,$im,0,0,0,0,$width,$height,$width,$height);
header("content-type: image/jpeg");
ImageJpeg($newimage,$thumb_img_path);
chmod("$thumb_img_path",0777);
}
header('Content-type: image/jpeg');
imagejpeg($newimage);
die();
print "width: ".$width."Height: ".$height;
//header("Location: ".$back);