watermerk

Gesponsorde koppelingen

PHP script bestanden

  1. watermerk

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?
#####################################################
#####################################################
##                                                 ##
##        Image script by Laurens A. Laman.        ##
##      This script loads a picture and puts a     ##
##    Watermark onto it. It also resizes it if     ##
##    you like. It displays the picture on your    ##
##  screen so you can put it in a <img src=> tag   ##
##                                                 ##
##           Script tested on PHP 4.4.1            ##
##                                                 ##
#####################################################
#####################################################

##################################################################
##################################################################
##                                                              ##
##                        How to use it?                        ##
##                                                              ##
##           This is very simple: just upload this script       ##
##  Then access it like <img src="Image.php?image=./test.jpg">  ##
##                  Or if you like to resize:                   ##
##      <img src="Image.php?image=./test.jpg&resize=Yes">       ##
##                                                              ##
##################################################################
##################################################################


###################################################
###################################################
##                                               ##
##                 Let's START:                  ##
##                                               ##
###################################################
###################################################


###################################################
###################################################
##                                               ##
##               Modify Variables:               ##
##                                               ##
###################################################
###################################################

$nieuwWidth = "150"; //--- The width of the picture to be resized. The height will be calculated automatically
$errpict    = "../jeugd/img/notfound.gif"; //--- The path of the picture if something goes wrong
$errtext    = "Picture not found"; //--- The error message if $_GET['image']; is empty
$watermark  = "../jeugd/img/watermerk2.gif"; //--- The location of the default watermark (horizontal)
$Watervert  = "../jeugd/img/watermerkvert.gif";//--- The location of the vertical watermark
$trans      = "30"; //-- Transparent in percent of the watermark (0-100)
###########################################################
###########################################################
##                                                       ##
## DO NOT MODIFY BENEATH UNLESS YOU KNOW WHAT YOUR DOING ##
##                                                       ##
###########################################################
###########################################################
//--- check if var 'resize' is empty else resize the image

If (!$_GET['resize']){
//--- check if var 'image' has been passed in the URL
if ($_GET['image'])
{

    //--- Content type
    header('content-type: image/jpeg');

    //--- set the path
    $pict = $_GET['image'];
    
    

    //--- watermark
    $path_watermark = $watermark;
    $watermark = imagecreatefromgif($path_watermark);
    $watermark_width = imagesx($watermark);
    $watermark_height = imagesy($watermark);

    //--- check that file exists
    if(!file_exists($pict)) {
    $pict=$errpict;
    }

    

    //--- image
            $ext=explode('.',$pict);
            $ext_check=count($ext);
            $ext=$ext[count($ext)-1];
            $ext = strtolower($ext);
    //--- use the proper imagecreate
    if     ($ext=="jpg"){$image = imagecreatefromjpeg($pict)or die('Cannot Create image');}
    elseif ($ext=="gif"){$image = imagecreatefromgif($pict)or die('Cannot Create image');}
    elseif ($ext=="png"){$image = imagecreatefrompng($pict)or die('Cannot Create image');}
    elseif ($ext=="bmp"){$image = imagecreatefrombmp($pict)or die('Cannot Create image');}
    else                {$image = imagecreatefromgif($errpict)or die('Cannot Create image');}//--- if file is not a picture then show error
    
    
    
    list($width, $height) = getimagesize($pict);
    $left = $width - $watermark_width;
    $top = $height - $watermark_height;    

    //--- merge watermark + image
    if ($width > $watermark_width){
    imagecopymerge($image, $watermark, $left, $top, 0, 0, $watermark_width, $watermark_height, $trans);
   }
else{
    //--- Vertical watermark if the width of the image is too small
   $watermark = imagecreatefromgif($Watervert);
    $watermark_width = imagesx($watermark);
    $watermark_height = imagesy($watermark);
    $left = $width - $watermark_width;
    $top = "0" ;
    if ($height > $watermark_height){//--- and if the image is too small for both watermarks, then show nothing
    imagecopymerge($image, $watermark, $left, $top, 0, 0, $watermark_width, $watermark_height, $trans);
    }
   }


    //--- print image
    imagejpeg($image);

    //--- destroy image + watermark
    imagedestroy($image);
    imagedestroy($watermark);
}

else {//--- Show error if var 'image' is empty

$text =  $errtext;
   $width = strlen($text) * 8.3;
    $height = 16;
    $font = 4;
$txtimg = imagecreate($width, $height);
imagecolorallocate($txtimg, 255, 0, 0);
$txtcolor = imagecolorallocate($txtimg, 255,255,255);
imagestring($txtimg, $font, 0, 0, $text, $txtcolor)or die ("Cannot Create image");
    
    //--- Content type
    header("Content-Type: image/jpeg");  
    //-- show img
    imagejpeg($txtimg);  
    //-- destroy img
    imagedestroy($txtimg);  

}
}
else{
if($_GET['image'])
{

//--- File and new size
$filename = $_GET['image'];

//--- check that file exists
    if(!file_exists($filename)) {$filename=$errpict;}




//--- Content type
header('Content-type: image/jpeg');

//--- Get new sizes
list($width, $height) = getimagesize($filename);
$percent = $height / $width;
$new_width = "150";
$new_height = "150" * $percent;
if ($newheight > "150"){
$percent = $width / $height;
$new_height = "150";
$new_width = "150" * $percent;
}


//--- Load
$thumb = imagecreatetruecolor($new_width, $new_height);


            $ext=explode('.',$filename);
            $ext_check=count($ext);
            $ext=$ext[count($ext)-1];
            $ext = strtolower($ext);
    //--- use the proper imagecreate
    if     ($ext=="jpg"){$source = imagecreatefromjpeg($filename)or die('Cannot Create image'); }
    elseif ($ext=="gif"){$source = imagecreatefromgif($filename)or die('Cannot Create image'); }
    elseif ($ext=="png"){$source = imagecreatefrompng($filename)or die('Cannot Create image'); }
    elseif ($ext=="bmp"){$source = imagecreatefrombmp($filename)or die('Cannot Create image'); }
    else{                $source = imagecreatefromgif($errpict)or die('Cannot Create image');}//--- if file is not a picture then show error


//--- Resize

imagecopyresized($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);


    //--- add watermark
    $path_watermark = $watermark;
    $watermark = imagecreatefromgif($path_watermark);
    $watermark_width = imagesx($watermark);
    $watermark_height = imagesy($watermark);
    $left = $new_width - $watermark_width;
    $top = $new_height - $watermark_height;
   if ($new_width > $watermark_width){
    imagecopymerge($thumb, $watermark, $left, $top, 0, 0, $watermark_width, $watermark_height, $trans);
   }
else{
    //--- Vertical watermark if the width of the image is too small
    $watermark = imagecreatefromgif($Watervert);
    $watermark_width = imagesx($watermark);
    $watermark_height = imagesy($watermark);
    $left = ($new_width - $watermark_width);
    $top = "0" ;
    if ($new_height > $watermark_height){//--- and if the image is too small for both watermarks, then show nothing
    imagecopymerge($thumb, $watermark, $left, $top, 0, 0, $watermark_width, $watermark_height, $trans);
    }
   }

//--- Output
imagejpeg($thumb);

}

else
{//--- Show error if var 'image' is empty
$text =  $errtext;
   $width = strlen($text) * 8.3;
    $height = 16;
    $font = 4;
$txtimg = imagecreate($width, $height);
imagecolorallocate($txtimg, 255, 0, 0);
$txtcolor = imagecolorallocate($txtimg, 255,255,255);
imagestring($txtimg, $font, 0, 0, $text, $txtcolor)or die ("Cannot Create image");
    
    //--- Content type
    header("Content-Type: image/jpeg");  
    //-- show img
    imagejpeg($txtimg);  
    //-- destroy img
    imagedestroy($txtimg);  
}

}
//--- end resize
?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.