Geen png en gif tijden upload.
In de map img/watermerk.png staat heel netjes de file.
In de map img/uploadmap worden alle files geupload.
Maar de files worden niet omgezet naar een *.png bestand waardoor ook het watermerk niet over de foto's heen gaat.
Tevens als ik gewoon losse *.gif en *.png bestanden upload krijg ik volledig zwarte plaatjes te zien.
Heeft iemand een idee waar ik moet zoeken in me script?
<code>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
//Action to upload a new image
if(($_GET['action']) == "upload")
{
//So when we should upload a file (because the entry ain't empty):
//Image upload
foreach ($_FILES["pictures"]["error"] as $key => $error)
{
$adv = $_GET['adv'];
if ($error == UPLOAD_ERR_OK)
{
$rand1 = rand(1000,4000);
$rand2 = rand(1000,9999);
$activationcode = "".$rand1."".$rand2."";
$maxkb = 4194304;
//Watermark
$watermerkurl = "../../../img/watermerk.png";
//Upload path
$path = "../../../img/uploadmap/";
//Width of the image (in pixels
$user_breedte = "500";
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name1 = $_FILES["pictures"]["name"][$key];
$name = "".$activationcode."".$name1."";
//Strip the whitespaces from the name, replace them with _
$replacedname = preg_replace('/ /', '_'.$activationcode.'', $name);
// move_uploaded_file($tmp_name, "$path$replacedname");
//Upload the image
move_uploaded_file($tmp_name, $path . $replacedname);
//Add the watermark
$watermerk = imagecreatefrompng($watermerkurl);
$watermerk_width = imagesx($watermerk);
$watermerk_height = imagesy($watermerk);
imagecreatetruecolor($watermerk_width, $watermerk_height);
list($breedte, $hoogte, $image_type) = getimagesize($path . $replacedname);
$image_ratio = $hoogte / $breedte;
if($image_ratio > 1)
{
$rs_breedte = $user_breedte;
$rs_hoogte = $user_breedte * $image_ratio;
}
else
{
$rs_hoogte = $user_breedte;
$rs_breedte = $user_breedte / $image_ratio;
}
$resize = imagecreatetruecolor($rs_breedte, $rs_hoogte);
$source = imagecreatefromjpeg($path . $replacedname);
imagecopyresized($resize, $source, 0, 0, 0, 0, $rs_breedte, $rs_hoogte, $breedte, $hoogte);
//Afbeelding opslaan
imagejpeg($resize, $path . $replacedname);
$image = imagecreatefromjpeg($path . $replacedname);
$size = getimagesize($path . $replacedname);
//Watermerk toevoegen
$xas = $size[0] - $watermerk_width - 5;
$yas = 5;
//--- overschrijf het 'geuploade bestand' en voeg watermerk toe
imagecopymerge($image, $watermerk, $xas, $yas, 0, 0, $watermerk_width, $watermerk_height, 100);
//--- upload image
imagejpeg($image, $path . $_FILES['pictures']['name']); // max. kwaliteit
imagedestroy($image);
imagedestroy($watermerk);
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name1 = $_FILES["pictures"]["name"][$key];
$name = "".$activationcode."".$name1."";
//Strip the whitespaces from the name, replace them with _
$replacedname = preg_replace('/ /', '_'.$activationcode.'', $name);
move_uploaded_file($tmp_name, "$path$replacedname");
$query_image = "INSERT INTO images (image, advertisement_id)
VALUES ('".$replacedname."',
(SELECT advertisement_id FROM advertisement WHERE code = '".$adv."'))";
$insert_image = mysql_query($query_image)or die(mysql_error());
}
}
//Message that the image has been uploaded!
echo '<h2>Afbeelding geupload!</h2>';
echo '<p>De afbeelding is succesvol geupload.</p>';
echo '<a href="index.php?adv=' . $adv . '">Terug</a>';
exit;
}
?>
//Action to upload a new image
if(($_GET['action']) == "upload")
{
//So when we should upload a file (because the entry ain't empty):
//Image upload
foreach ($_FILES["pictures"]["error"] as $key => $error)
{
$adv = $_GET['adv'];
if ($error == UPLOAD_ERR_OK)
{
$rand1 = rand(1000,4000);
$rand2 = rand(1000,9999);
$activationcode = "".$rand1."".$rand2."";
$maxkb = 4194304;
//Watermark
$watermerkurl = "../../../img/watermerk.png";
//Upload path
$path = "../../../img/uploadmap/";
//Width of the image (in pixels
$user_breedte = "500";
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name1 = $_FILES["pictures"]["name"][$key];
$name = "".$activationcode."".$name1."";
//Strip the whitespaces from the name, replace them with _
$replacedname = preg_replace('/ /', '_'.$activationcode.'', $name);
// move_uploaded_file($tmp_name, "$path$replacedname");
//Upload the image
move_uploaded_file($tmp_name, $path . $replacedname);
//Add the watermark
$watermerk = imagecreatefrompng($watermerkurl);
$watermerk_width = imagesx($watermerk);
$watermerk_height = imagesy($watermerk);
imagecreatetruecolor($watermerk_width, $watermerk_height);
list($breedte, $hoogte, $image_type) = getimagesize($path . $replacedname);
$image_ratio = $hoogte / $breedte;
if($image_ratio > 1)
{
$rs_breedte = $user_breedte;
$rs_hoogte = $user_breedte * $image_ratio;
}
else
{
$rs_hoogte = $user_breedte;
$rs_breedte = $user_breedte / $image_ratio;
}
$resize = imagecreatetruecolor($rs_breedte, $rs_hoogte);
$source = imagecreatefromjpeg($path . $replacedname);
imagecopyresized($resize, $source, 0, 0, 0, 0, $rs_breedte, $rs_hoogte, $breedte, $hoogte);
//Afbeelding opslaan
imagejpeg($resize, $path . $replacedname);
$image = imagecreatefromjpeg($path . $replacedname);
$size = getimagesize($path . $replacedname);
//Watermerk toevoegen
$xas = $size[0] - $watermerk_width - 5;
$yas = 5;
//--- overschrijf het 'geuploade bestand' en voeg watermerk toe
imagecopymerge($image, $watermerk, $xas, $yas, 0, 0, $watermerk_width, $watermerk_height, 100);
//--- upload image
imagejpeg($image, $path . $_FILES['pictures']['name']); // max. kwaliteit
imagedestroy($image);
imagedestroy($watermerk);
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name1 = $_FILES["pictures"]["name"][$key];
$name = "".$activationcode."".$name1."";
//Strip the whitespaces from the name, replace them with _
$replacedname = preg_replace('/ /', '_'.$activationcode.'', $name);
move_uploaded_file($tmp_name, "$path$replacedname");
$query_image = "INSERT INTO images (image, advertisement_id)
VALUES ('".$replacedname."',
(SELECT advertisement_id FROM advertisement WHERE code = '".$adv."'))";
$insert_image = mysql_query($query_image)or die(mysql_error());
}
}
//Message that the image has been uploaded!
echo '<h2>Afbeelding geupload!</h2>';
echo '<p>De afbeelding is succesvol geupload.</p>';
echo '<a href="index.php?adv=' . $adv . '">Terug</a>';
exit;
}
?>
</code>
Oorzaak: imagecreatefromjpeg
Zie php.net hoe je het dient op te lossen
Ik zal er eens naar kijken.