I'm kind of lost here. I don't know if I should use your code only or a mix of your code and the old one
I added your code in the middle of the code below. Is there a way you can show in the code below. I'm kind of a beginner with this stuff. Just wanted a way to crop instead of using wrong proportions
PHP Code:
// Upload File To Web Server
$pPath = "photos/";
if (is_uploaded_file($_FILES['thefile']['tmp_name'])){
move_uploaded_file($_FILES['thefile']['tmp_name'], $pPath.$_FILES['thefile']['name']) or die ("CouldnĄt copy");
header("Location: members.php");
// Define the file
$filename = $pPath.$_FILES['thefile']['name'];
$thumbname = "TN_".$_FILES['thefile']['name'];
$thumbnail = $pPath.$thumbname;
//___________________
// Crop dimensions.
$width = 100;
$height = 100;
// Set the path to the image to resize
$input_image = "$filename";
// Get the size of the original image into an array
$size = getimagesize( $input_image );
// Prepare canvas
$canvas = imagecreatetruecolor( $width, $height );
// Create a new image in the memory from the file
$cropped = imagecreatefromjpeg( $input_image );
// Prepare image crop - center the crop on the image
$newwidth = $size[0] / 2;
$newheight = $size[1] / 2;
$cropLeft = ( $newwidth/2 ) - ( $width/2 );
$cropHeight = ( $newheight/2 ) - ( $height/2 );
// Generate the cropped image
imagecopyresized( $canvas, $cropped, 0,0, $cropLeft, $cropHeight, $size[0], $size[1], $newwidth, $newheight );
// Save the cropped image as cropped.jpg
imagejpeg( $canvas, "cropped.jpg" );
// Clear the memory of the tempory images
imagedestroy( $canvas );
imagedestroy( $cropped );
//_____________________________
// Set a maximum height and width
$width = $Photo_Width;
$height = $Photo_Height;
// Determine File Name
$myfilename = substr($filename, 3);
$mythumbname = substr($thumbnail, 3);
//Create INSERT query
$qry = "UPDATE members SET content='$content', photo_path='$myfilename', thumb_path='$mythumbname' WHERE member_id='$member_id'";
$result = mysql_query($qry) or die("Query failed");
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if ($width && ($width_orig < $height_orig)) {
$per = (100*$width)/$width_orig;
$per = round($per);
$height = ($height_orig*$per)/100;
echo $height;
//($height / $height_orig) * $width_orig;
if ($width < 100){
$pre = 100 - $width;
$width = $width + $pre;
//echo $width;
}
if ($width > 100){
$pre = $width - 100;
$width = $width - $pre;
//echo $pre;
}
} else {
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, $pPath.$thumbname, 100);
$pasto = getimagesize($pPath.$thumbname);
link($pPath.$_FILES['thefile']['name']);
//unlink($pPath.$_FILES['thefile']['name']);
$user = 1;
$elwidth = $pasto[0];
$elheight = $pasto[1];
}
Bookmarks