Sorry for the late reaction, I had to work today.
The upload and resize/watermark part are in the image.func.php;
<?php
function upload_image($image_temp, $image_ext, $album_id) {
$album_id = (int)$album_id;
$image_name = $_FILES['image'] ['name'];
mysql_query("INSERT INTO `images` VALUES ('', '$image_name', '".$_SESSION['user_id']."', '$album_id', UNIX_TIMESTAMP(), '$image_ext')");
$image_id = mysql_insert_id();
$image_file = $image_id.'.'.$image_ext;
$source_image = $image_temp;
$destination = 'uploads/'.$album_id.'/'.$image_file;
$tn_w = 900;
$tn_h = 600;
$quality = 100;
$wmsource = 'watermark.png';
image_handler($source_image,$destination,$tn_w,$tn_h,$quality,$wmsource);
create_thumb('uploads/'.$album_id.'/', $image_file, 'uploads/thumbs/'.$album_id.'/');
}
function image_handler($source_image,$destination,$tn_w,$tn_h,$quality = 80,$wmsource) {
#find out what type of image this is
$info = getimagesize($source_image);
$imgtype = image_type_to_mime_type($info[2]);
#assuming the mime type is correct
switch ($imgtype) {
case 'image/jpeg':
$source = imagecreatefromjpeg($source_image);
break;
case 'image/gif':
$source = imagecreatefromgif($source_image);
break;
case 'image/png':
$source = imagecreatefrompng($source_image);
break;
default:
die('Invalid image type.');
}
#Figure out the dimensions of the image and the dimensions of the desired thumbnail
$src_w = imagesx($source);
$src_h = imagesy($source);
$src_ratio = $src_w/$src_h;
#Do some math to figure out which way we'll need to crop the image
#to get it proportional to the new size, then crop or adjust as needed
if ($tn_w/$tn_h > $src_ratio) {
$tn_w = $tn_h * $src_ratio;
} else {
$tn_h = $tn_w / $src_ratio;
}
$newpic = imagecreatetruecolor($tn_w, $tn_h);
imagecopyresampled($newpic, $source, 0, 0, 0, 0, $tn_w, $tn_h, $src_w, $src_h);
#if we need to add a watermark
if($wmsource) {
#find out what type of image the watermark is
$info = getimagesize($wmsource);
$imgtype = image_type_to_mime_type($info[2]);
#assuming the mime type is correct
switch ($imgtype) {
case 'image/jpeg':
$watermark = imagecreatefromjpeg($wmsource);
break;
case 'image/gif':
$watermark = imagecreatefromgif($wmsource);
break;
case 'image/png':
$watermark = imagecreatefrompng($wmsource);
break;
default:
return false;
}
#if we're adding a watermark, figure out the size of the watermark
#and then place the watermark image on the bottom right of the image
imagealphablending($newpic, true);
$img_w = imagesx($newpic);
$img_h = imagesy($newpic);
$wm_w = imagesx($watermark);
$wm_h = imagesy($watermark);
$dst_x = ($img_w / 2) - ($wm_w / 2); // For centering the watermark on any image
$dst_y = ($img_h / 2) - ($wm_h / 2); // For centering the watermark on any image
imagecopy($newpic, $watermark, $dst_x, $dst_y, 0, 0, $wm_w, $wm_h);
}
if(Imagejpeg($newpic,$destination,$quality)) {
return true;
}
return false;
}
?>
And the file where these functions are used in is;
<?php
if (isset($_FILES['image'], $_POST['album_id'])) {
$image_name = $_FILES['image'] ['name'];
$image_size = $_FILES['image'] ['size'];
$image_temp = $_FILES['image'] ['tmp_name'];
$allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
$chunks = explode('.', $image_name);
$image_ext = end($chunks);
$image_ext = strtolower($image_ext);
$album_id = $_POST['album_id'];
$errors = array();
if (!empty($errors)) {
foreach ($errors as $error) {
echo $error, '<br />';
}
} else {
upload_image($image_temp, $image_ext, $album_id);
header('Location: view_album.php?album_id='.$album_id);
exit();
}
include 'template/header.php';
if (empty($image_name) || empty($album_id)) {
$errors[] = 'Niet alles is ingevuld';
} else {
if (in_array($image_ext, $allowed_ext) === false) {
$errors[] = 'Bestandsnaam is niet toegestaan.';
}
if ($image_size > 52428800) {
$errors[] = 'Je kan maximaal 5mb uploaden.';
}
if (album_check($album_id) === false) {
$errors[] = 'Er kan niet naar dit album worden geupload.';
}
}
}
$albums = get_albums();
if (empty($albums)) {
echo '<p>Je hebt nog geen albums. <a href="create_album.php">Maak een album.</a></p>';
} else {
?>
<h3>Upload foto</h3>
<form action="" method="post" enctype="multipart/form-data">
<p>Kies een foto:<br /><input type="file" name="image" /></p>
<p>
Kies een album:<br />
<select name="album_id">
<?php
foreach ($albums as $album) {
echo '<option value="', $album['id'], '">', $album['name'], '</option>';
}
?>
</select>
</p>
<p><input type="submit" value="Upload" /></p>
</form>
I hope you can see what the problem is, I don't...