heb een script gevonden waarmee ik een plaatje kan verkleinen, het lukt me alleen niet op het verkleinde plaatje vervolgens op te slaan un de database in het veld 'thumb'..hoe doe ik dit?
if ($_POST) {
// No image?
if (empty($_FILES['image']) OR $_FILES['image']['error'] != UPLOAD_ERR_OK) {
die ('<strong>Invalid image uploaded. Please go back and try again.</strong>');
}
$imagepath = $_FILES['image']['tmp_name'];
// Load image
$image = open_image($imagepath);
if ($image == false) {
die ('<strong>You uploaded an invalid image. Please go back and try again.</strong>');
}
// origineel opslaan
$destfile = $userimagedir.$_FILES["image"]["name"];
move_uploaded_file($imagepath,$destfile);
$sql = "update machine set userimage = '" . $_FILES["image"]["name"] . "' where id = $id";
//echo $sql;
$result = mysql_query($sql);
echo mysql_error();
//---
// Get original width and height
$width = imagesx($image);
$height = imagesy($image);
// Percentage?
if (!empty($_POST['percent']) AND is_numeric($_POST['percent'])) {
$percent = floatval($_POST['percent']);
$percent = $percent/100;
$new_width = $width * $percent;
$new_height = $height * $percent;
// New width? Calculate new height
} elseif (!empty($_POST['new_width']) AND is_numeric($_POST['new_width'])) {
$new_width = floatval($_POST['new_width']);
$new_height = $height * ($new_width/$width);
// New height? Calculate new width
} elseif (!empty($_POST['new_height']) AND is_numeric($_POST['new_height'])) {
$new_height = floatval($_POST['new_height']);
$new_width = $width * ($new_height/$height);
// New height and new width
} elseif (!empty($_POST['height']) AND is_numeric($_POST['height']) AND !empty($_POST['width']) AND is_numeric($_POST['width'])) {
$new_height = floatval($_POST['height']);
$new_width = floatval($_POST['width']);
} else {
die ('<strong>You didn\'t specify any resizing options.</strong>');
}
// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
788 views