Upload + text watermerk combineren
Alleen nu moet ik nog een uploadscript/classe en die dan combineren met het watermerk script zodat bij het uploaden van de foto het watermerkbalkje eronder komt te staan. Ik heb alleen geen idee hoe dit moet.
Ik heb al wel wat zitten proberen en heb het volgende voor elkaar gekregen:
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?
if (isset($_FILES['bestand'])) {
//De groote van het bestand vergelijken met het maximum
if ($_FILES['bestand']['size'] > 3024000){
exit("Je bestand " . $_FILES['bestand']['size'] . " bytes, het maximum toegelaten is 302400 bytes");
}
if($_FILES['bestand']['type'] == "image/jpeg" || $_FILES['bestand']['type'] == "image/pjpeg") {
$x = strtolower(substr($_FILES['bestand']['name'], -3));
// De naam van de file veranderen in bv. image0
$file_name = "photo-";
$n = 0;
// Check of file al bestaat, zo ja, filename verhogen
while (file_exists('bestanden/' . $file_name . $n . '.' . $x))
{
$n = $n + 1;
}
$file_name = $file_name . $n;
move_uploaded_file($_FILES['bestand']['tmp_name'],'bestanden/' . $file_name . '.' . $x);
chmod ('bestanden/' . $file_name . '.' . $x, 0777);
//kiezen
// $bg = "ffddee"; // hex representation of the color (i.e. #ffffff for white)
$out = "png"; // or "jpg" for jpg file output
$backgroundfile = "'bestanden/' . $file_name . '.' . $x"; // optional backgroundfile if you don't want to use a
color
//
// function to convert hex colorcode to decimal
//
function colordecode($hex){
$code[r] = hexdec(substr($hex, 0 ,2));
$code[g] = hexdec(substr($hex, 2 ,2));
$code[b] = hexdec(substr($hex, 4 ,2));
return $code;
} // end func colordecode
// create the resource id
$naam= "Pro-aviation.nl // Copyright by ".$_POST['naam'] . " // " . $_POST['dag'] . "-" . $_POST['maand'] . "-" .
$_POST['jaar'] . " // " . $_POST['locatie'] . " // " . $_POST['reg'] . " // " . $_POST['toestel'] . " // " .
$_POST['maatschappij'];
header ("Content-type: image/png");
$im = @imagecreatetruecolor(800, 14);
imagealphablending($im, true);
$text_color = imagecolorallocatealpha($im, 255, 255, 255,10);
$image_id = imagestring($im, 2, 2, 0, "$naam", $text_color);
// create the resource id
$image_big = imageCreateFromjpeg('bestanden/' . $file_name . '.' . $x);
// get image size
$im_Xx = Imagesx($image_big);
$im_Yy = Imagesy($image_big);
// get image size
$im_X = ImageSX($image_id);
$im_Y = ImageSY($image_id);
// create a truecolor background image of the right size
// or use a background image like this
$backgroundimage = imageCreateFromjpeg('bestanden/' . $file_name . '.' . $x);
// $backgroundimage = imagecreatetruecolor($im_X, $im_Y);
// get the desired backgroundcolor:
// don't use this if you want to use a background image
$code = colordecode($bg);
$backgroundcolor = ImageColorAllocate($backgroundimage, $code[r], $code[g], $code[b]);
ImageFilledRectangle($backgroundimage, 0, $im_Yy-14, $im_Xx, $im_Yy, $backgroundcolor);
// merge the two together with alphablending on!
ImageAlphaBlending($backgroundimage, true);
// coordinaten x,y,
imagecopy($backgroundimage, $image_id, 0, $im_Yy-14, 0, 0, $im_X, $im_Y);
// output the image:
if($output == "jpg"){
Header( "Content-type: image/jpeg");
ImageJPEG($backgroundimage);
}
else{
Header( "Content-type: image/png");
ImagePNG($backgroundimage);
}
// destroy the memory
ImageDestroy($backgroundimage);
ImageDestroy($image_id);
echo "Het bestand is succesvol opgeslagen";
} else {
echo "Het bestands formaat word niet ondersteund.<br> Alleen jpg word toegelaten.";
}
}
?>
<table border="0">
<form action="" enctype="multipart/form-data" method="post">
<tr><td>Naam:</td>
<td> <select name="naam" size="1">
<option value="Meneer X">Meneer X</option>
</select>
<br /></td></tr>
<tr><td>Toestel:</td><td> <input type="text" name="toestel" /><br /></td></tr>
<tr><td>Registratie:</td><td> <input type="text" name="reg" /><br /></td></tr>
<tr><td>Maatschappij:</td><td> <input type="text" name="maatschappij" /><br /></td></tr>
<tr>
<td>Datum:</td>
<td>
<input type="text" size="1" maxlength="2" name="dag" />
<input type="text" size="3" maxlength="2" name="maand" />
<input type="text" size="5" maxlength="4" name="jaar" /><br /></td></tr>
<tr><td>Locatie (ICAO):</td><td> <input size="5" maxlength="4" type="text" name="locatie" /><br /></td></tr>
<tr><td colspan="2">
<input type="file" name="bestand"></td></tr>
</table>
<input type="submit" name="submit" value="Upload" /><br />
</form>
if (isset($_FILES['bestand'])) {
//De groote van het bestand vergelijken met het maximum
if ($_FILES['bestand']['size'] > 3024000){
exit("Je bestand " . $_FILES['bestand']['size'] . " bytes, het maximum toegelaten is 302400 bytes");
}
if($_FILES['bestand']['type'] == "image/jpeg" || $_FILES['bestand']['type'] == "image/pjpeg") {
$x = strtolower(substr($_FILES['bestand']['name'], -3));
// De naam van de file veranderen in bv. image0
$file_name = "photo-";
$n = 0;
// Check of file al bestaat, zo ja, filename verhogen
while (file_exists('bestanden/' . $file_name . $n . '.' . $x))
{
$n = $n + 1;
}
$file_name = $file_name . $n;
move_uploaded_file($_FILES['bestand']['tmp_name'],'bestanden/' . $file_name . '.' . $x);
chmod ('bestanden/' . $file_name . '.' . $x, 0777);
//kiezen
// $bg = "ffddee"; // hex representation of the color (i.e. #ffffff for white)
$out = "png"; // or "jpg" for jpg file output
$backgroundfile = "'bestanden/' . $file_name . '.' . $x"; // optional backgroundfile if you don't want to use a
color
//
// function to convert hex colorcode to decimal
//
function colordecode($hex){
$code[r] = hexdec(substr($hex, 0 ,2));
$code[g] = hexdec(substr($hex, 2 ,2));
$code[b] = hexdec(substr($hex, 4 ,2));
return $code;
} // end func colordecode
// create the resource id
$naam= "Pro-aviation.nl // Copyright by ".$_POST['naam'] . " // " . $_POST['dag'] . "-" . $_POST['maand'] . "-" .
$_POST['jaar'] . " // " . $_POST['locatie'] . " // " . $_POST['reg'] . " // " . $_POST['toestel'] . " // " .
$_POST['maatschappij'];
header ("Content-type: image/png");
$im = @imagecreatetruecolor(800, 14);
imagealphablending($im, true);
$text_color = imagecolorallocatealpha($im, 255, 255, 255,10);
$image_id = imagestring($im, 2, 2, 0, "$naam", $text_color);
// create the resource id
$image_big = imageCreateFromjpeg('bestanden/' . $file_name . '.' . $x);
// get image size
$im_Xx = Imagesx($image_big);
$im_Yy = Imagesy($image_big);
// get image size
$im_X = ImageSX($image_id);
$im_Y = ImageSY($image_id);
// create a truecolor background image of the right size
// or use a background image like this
$backgroundimage = imageCreateFromjpeg('bestanden/' . $file_name . '.' . $x);
// $backgroundimage = imagecreatetruecolor($im_X, $im_Y);
// get the desired backgroundcolor:
// don't use this if you want to use a background image
$code = colordecode($bg);
$backgroundcolor = ImageColorAllocate($backgroundimage, $code[r], $code[g], $code[b]);
ImageFilledRectangle($backgroundimage, 0, $im_Yy-14, $im_Xx, $im_Yy, $backgroundcolor);
// merge the two together with alphablending on!
ImageAlphaBlending($backgroundimage, true);
// coordinaten x,y,
imagecopy($backgroundimage, $image_id, 0, $im_Yy-14, 0, 0, $im_X, $im_Y);
// output the image:
if($output == "jpg"){
Header( "Content-type: image/jpeg");
ImageJPEG($backgroundimage);
}
else{
Header( "Content-type: image/png");
ImagePNG($backgroundimage);
}
// destroy the memory
ImageDestroy($backgroundimage);
ImageDestroy($image_id);
echo "Het bestand is succesvol opgeslagen";
} else {
echo "Het bestands formaat word niet ondersteund.<br> Alleen jpg word toegelaten.";
}
}
?>
<table border="0">
<form action="" enctype="multipart/form-data" method="post">
<tr><td>Naam:</td>
<td> <select name="naam" size="1">
<option value="Meneer X">Meneer X</option>
</select>
<br /></td></tr>
<tr><td>Toestel:</td><td> <input type="text" name="toestel" /><br /></td></tr>
<tr><td>Registratie:</td><td> <input type="text" name="reg" /><br /></td></tr>
<tr><td>Maatschappij:</td><td> <input type="text" name="maatschappij" /><br /></td></tr>
<tr>
<td>Datum:</td>
<td>
<input type="text" size="1" maxlength="2" name="dag" />
<input type="text" size="3" maxlength="2" name="maand" />
<input type="text" size="5" maxlength="4" name="jaar" /><br /></td></tr>
<tr><td>Locatie (ICAO):</td><td> <input size="5" maxlength="4" type="text" name="locatie" /><br /></td></tr>
<tr><td colspan="2">
<input type="file" name="bestand"></td></tr>
</table>
<input type="submit" name="submit" value="Upload" /><br />
</form>
Alleen het werkt nog niet. De foto wordt wel geupload, maar ik krijg geen balkje onderin.
Hier de dingen die niet werken:
- Copyrightbalkje wordt niet gemaakt en komt niet op foto
- krijg de volgende foutmelding als ik op upload klik (foto wordt wel op de server gezet dan):
Code (php)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
<br />
<b>Warning</b>: imagesx(): supplied argument is not a valid Image resource in <b>/usr/home/deb7560/domains/pro-aviation.nl/public_html/GD/text/uploadtest.php</b> on line <b>65</b><br />
<br />
<b>Warning</b>: imagesy(): supplied argument is not a valid Image resource in <b>/usr/home/deb7560/domains/pro-aviation.nl/public_html/GD/text/uploadtest.php</b> on line <b>66</b><br />
<br />
<b>Warning</b>: imagecopy(): supplied argument is not a valid Image resource in <b>/usr/home/deb7560/domains/pro-aviation.nl/public_html/GD/text/uploadtest.php</b> on line <b>82</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /usr/home/deb7560/domains/pro-aviation.nl/public_html/GD/text/uploadtest.php:65) in <b>/usr/home/deb7560/domains/pro-aviation.nl/public_html/GD/text/uploadtest.php</b> on line <b>90</b><br />
PNG
<b>Warning</b>: imagesx(): supplied argument is not a valid Image resource in <b>/usr/home/deb7560/domains/pro-aviation.nl/public_html/GD/text/uploadtest.php</b> on line <b>65</b><br />
<br />
<b>Warning</b>: imagesy(): supplied argument is not a valid Image resource in <b>/usr/home/deb7560/domains/pro-aviation.nl/public_html/GD/text/uploadtest.php</b> on line <b>66</b><br />
<br />
<b>Warning</b>: imagecopy(): supplied argument is not a valid Image resource in <b>/usr/home/deb7560/domains/pro-aviation.nl/public_html/GD/text/uploadtest.php</b> on line <b>82</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /usr/home/deb7560/domains/pro-aviation.nl/public_html/GD/text/uploadtest.php:65) in <b>/usr/home/deb7560/domains/pro-aviation.nl/public_html/GD/text/uploadtest.php</b> on line <b>90</b><br />
PNG
Er kunnen best nog wat meerfouten in zitten, meld die maar. Ik ben niet goed in PHP (geef het maar gewoon toe) en hoop dat iemand mij kan helpen om het werkende te krijgen.
Gewijzigd op 01/01/1970 01:00:00 door Ruud
Er zijn nog geen reacties op dit bericht.