Watermerk png niet transparant
Echter blijft hij lelijke zwarte achtergrond geven. Wat doe ik fout?
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$path_watermerk = "images/watermerk.png"; // dit MOET een transparante .png zijn!!!
//--- transparante watermerk
$watermerk = imagecreatefrompng($path_watermerk);
$watermerk_width = imagesx($watermerk);
$watermerk_height = imagesy($watermerk);
imagecreatetruecolor($watermerk_width, $watermerk_height);
//--- orriginele image
$image = imagecreatefromjpeg( "{$tumbpath}{$fnamefinal}" );
$size = getimagesize( "{$tumbpath}{$fnamefinal}" );
//--- dit is voor rechts boven
$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, 50);
//--- upload image
imagejpeg($image, "{$tumbpath}{$fnamefinal}"); // max. kwaliteit
imagedestroy($image);
imagedestroy($watermerk);
?>
$path_watermerk = "images/watermerk.png"; // dit MOET een transparante .png zijn!!!
//--- transparante watermerk
$watermerk = imagecreatefrompng($path_watermerk);
$watermerk_width = imagesx($watermerk);
$watermerk_height = imagesy($watermerk);
imagecreatetruecolor($watermerk_width, $watermerk_height);
//--- orriginele image
$image = imagecreatefromjpeg( "{$tumbpath}{$fnamefinal}" );
$size = getimagesize( "{$tumbpath}{$fnamefinal}" );
//--- dit is voor rechts boven
$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, 50);
//--- upload image
imagejpeg($image, "{$tumbpath}{$fnamefinal}"); // max. kwaliteit
imagedestroy($image);
imagedestroy($watermerk);
?>
Gebruik imagecreatefrompng
Ik haalde image en watermerk door elkaar.
Gewijzigd op 16/08/2016 19:50:32 door Michael -
https://www.sitepoint.com/watermark-images-php
Die werkt niet, dus heb ik er dit van gemaakt :
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
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
<?php
$original = 'Antarctica.jpg';
$png = 'Home.png';
// Create a reference to the uploaded jpg
$background = imagecreatefromjpeg($original);
$size = getimagesize($original);
// Enable alphablending for the jpg
imagealphablending($background, true);
// Create a reference to the watermark png
$watermark = imagecreatefrompng($png);
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$dest_x = $size[0] - $watermark_width - 0;
$dest_y = $size[1] - $watermark_height - 0;
// Copy the watermark into the background
imagecopy($background, $watermark, $dest_x,$dest_y,0,0,$watermark_width,$watermark_height);
// Output the image to the browser
header('Content-type: image/jpeg');
imagejpeg($background);
// Or output to file
//imagejpeg($background, "result.jpg"); // max. kwaliteit
// Free up resources
imagedestroy($background);
imagedestroy($watermark);
?>
$original = 'Antarctica.jpg';
$png = 'Home.png';
// Create a reference to the uploaded jpg
$background = imagecreatefromjpeg($original);
$size = getimagesize($original);
// Enable alphablending for the jpg
imagealphablending($background, true);
// Create a reference to the watermark png
$watermark = imagecreatefrompng($png);
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$dest_x = $size[0] - $watermark_width - 0;
$dest_y = $size[1] - $watermark_height - 0;
// Copy the watermark into the background
imagecopy($background, $watermark, $dest_x,$dest_y,0,0,$watermark_width,$watermark_height);
// Output the image to the browser
header('Content-type: image/jpeg');
imagejpeg($background);
// Or output to file
//imagejpeg($background, "result.jpg"); // max. kwaliteit
// Free up resources
imagedestroy($background);
imagedestroy($watermark);
?>
Resultaat hier :
http://adoptive.esy.es/watermark/
Adoptive Solution op 16/08/2016 18:39:23:
Zo te zien is de code hier opgehaald :
https://www.sitepoint.com/watermark-images-php
Die werkt niet, dus heb ik er dit van gemaakt :
Resultaat hier :
http://adoptive.esy.es/watermark/
https://www.sitepoint.com/watermark-images-php
Die werkt niet, dus heb ik er dit van gemaakt :
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
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
<?php
$original = 'Antarctica.jpg';
$png = 'Home.png';
// Create a reference to the uploaded jpg
$background = imagecreatefromjpeg($original);
$size = getimagesize($original);
// Enable alphablending for the jpg
imagealphablending($background, true);
// Create a reference to the watermark png
$watermark = imagecreatefrompng($png);
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$dest_x = $size[0] - $watermark_width - 0;
$dest_y = $size[1] - $watermark_height - 0;
// Copy the watermark into the background
imagecopy($background, $watermark, $dest_x,$dest_y,0,0,$watermark_width,$watermark_height);
// Output the image to the browser
header('Content-type: image/jpeg');
imagejpeg($background);
// Or output to file
//imagejpeg($background, "result.jpg"); // max. kwaliteit
// Free up resources
imagedestroy($background);
imagedestroy($watermark);
?>
$original = 'Antarctica.jpg';
$png = 'Home.png';
// Create a reference to the uploaded jpg
$background = imagecreatefromjpeg($original);
$size = getimagesize($original);
// Enable alphablending for the jpg
imagealphablending($background, true);
// Create a reference to the watermark png
$watermark = imagecreatefrompng($png);
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$dest_x = $size[0] - $watermark_width - 0;
$dest_y = $size[1] - $watermark_height - 0;
// Copy the watermark into the background
imagecopy($background, $watermark, $dest_x,$dest_y,0,0,$watermark_width,$watermark_height);
// Output the image to the browser
header('Content-type: image/jpeg');
imagejpeg($background);
// Or output to file
//imagejpeg($background, "result.jpg"); // max. kwaliteit
// Free up resources
imagedestroy($background);
imagedestroy($watermark);
?>
Resultaat hier :
http://adoptive.esy.es/watermark/