# GD watermark problem

**URL:** <https://forum.kirupa.com/t/gd-watermark-problem/186807>\
**Category:** Uncategorized\
**Created:** [April 24, 2006, 7:27pm UTC](https://forum.kirupa.com/t/gd-watermark-problem/186807 "2006-04-24T19:27:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sWo0p](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sWo0p](https://forum.kirupa.com/u/sWo0p)\
**Post date:** [April 24, 2006, 7:27pm UTC](https://forum.kirupa.com/t/gd-watermark-problem/186807/1 "2006-04-24T19:27:18Z")

</div>

was working on a image uploadscript with resize and watermark section… script already works fine but i run a snag… my watermark section does’nt seem to work…

mybe you guys can find de problem:

```php

<?
//* Lees naam afbeelding uit url en koppel VIEW tag aan template *//
if ($_GET['afbeelding']){  
  
	$path_watermerk = $wtrm_dir . "/water_sWo0p.png"; 
	//* watermerk test echo "<img src=\"" . $path_watermerk . "\">";
	$watermerk = imagecreatefrompng($path_watermerk);  
    $watermerk_width = imagesx($watermerk);  
    $watermerk_height = imagesy($watermerk);

    $image = imagecreatefromjpeg($upl_dir . "\\" . $_GET['afbeelding']);  
    $size = getimagesize($upl_dir . $_GET['afbeelding']);  
    $xas = $size[0] - $watermerk_width - 5;  
    $yas = 5;  
 
    imagecopymerge($image, $watermerk, $xas, $yas, 0, 0, $watermerk_width, $watermerk_height, 100);
 
}  
else  
    echo "Geen naam meegegeven in URL.";
	
	header('content-type: image/jpeg');
    $afb = imagejpeg($image); //imagejpeg($image);
	$afbeelding = '<img src=" '.$afb.' " width="400" border="1" />';
    $tpl->assign("VIEW_IMAGE", "$afbeelding");
?>

```

there is a template system in my script but you guys can work around that… :thumb2:

---

<div class="post-metadata">

**Author:** ![teiz77](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/teiz77/32/771_2.png) [@teiz77](https://forum.kirupa.com/u/teiz77)\
**Post date:** [April 25, 2006, 7:25am UTC](https://forum.kirupa.com/t/gd-watermark-problem/186807/2 "2006-04-25T07:25:11Z")

</div>

```php
<? 
//* Lees naam afbeelding uit url en koppel VIEW tag aan template *//
if ($_GET['afbeelding']){  
  
    $path_watermerk = $wtrm_dir . "/water_sWo0p.png";
    //* watermerk test echo "<img src=\"" . $path_watermerk . "\">";
    $watermerk = imagecreatefrompng($path_watermerk);  
    $watermerk_width = imagesx($watermerk);  
    $watermerk_height = imagesy($watermerk);

    $image = imagecreatefromjpeg($upl_dir . "/" . $_GET['afbeelding']);  
    $size = getimagesize($upl_dir. "/" . $_GET['afbeelding']);  
    $xas = $size[0] - $watermerk_width - 5;  
    $yas = 5;  
	imagecopy($image, $watermerk,$xas, $yas,0,0,$watermerk_width,$watermerk_height);

}  
else  
    echo "Geen naam meegegeven in URL.";
    
    header('content-type: image/jpeg');
    $afb = imagejpeg($image); //imagejpeg($image);
    $afbeelding = '<img src=" '.$afb.' " width="400" border="1" />';
    $tpl->assign("VIEW_IMAGE", "$afbeelding");
?> 

```

Try this… imagecopymerge doesn’t seem to support alpha channels. I also changed some slashes, otherwise the script couldn’t find the files.

---

<div class="post-metadata">

**Author:** ![sWo0p](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sWo0p](https://forum.kirupa.com/u/sWo0p)\
**Post date:** [April 25, 2006, 9:21pm UTC](https://forum.kirupa.com/t/gd-watermark-problem/186807/3 "2006-04-25T21:21:58Z")

</div>

i did’nt have the time to try it out yet, but knowing you it’ll work, thanks dude… but axplain what was wrong in my script… ?

---

<div class="post-metadata">

**Author:** ![Ankou](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ankou/32/1351_2.png) [@Ankou](https://forum.kirupa.com/u/Ankou)\
**Post date:** [April 26, 2006, 12:47am UTC](https://forum.kirupa.com/t/gd-watermark-problem/186807/4 "2006-04-26T00:47:26Z")

</div>

> [@sWo0p](#):
>
> i did’nt have the time to try it out yet, but knowing you it’ll work, thanks dude… but axplain what was wrong in my script… ?

According to teiz77 the following things were wrong (or not working):

> [@teiz77](#):
>
> Try this… imagecopymerge doesn’t seem to support alpha channels. I also changed some slashes, otherwise the script couldn’t find the files.

The imagecopymerge thing is pretty clear. If you need more info, look at the PHP manual on that. It usually does a good job of explaining possible issues (especially in the comments).

The slashes. Well you were using “\” when it should have been “/” for the path to the images. And there was one case where you didn’t have the “/” to separate the path from the file name:

The “\” vs. “/” problem:

```php
$image = imagecreatefromjpeg($upl_dir . "\\" . $_GET['afbeelding']);

```

The missing “/” - you needed this b/n $upl\_dir and $\_GET:

```php
$size = getimagesize($upl_dir . $_GET['afbeelding']);

```

(PHP code above is your code, the correction can be seen in teiz77’s code)

BTW - teiz77, I didn’t mean to jump in on your post here and “take over” but I figured I’d explain it incase sWo0p came back for an answer before you could reply. I hope that was okay (and I hope I didn’t miss anything).

---

<div class="post-metadata">

**Author:** ![teiz77](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/teiz77/32/771_2.png) [@teiz77](https://forum.kirupa.com/u/teiz77)\
**Post date:** [April 26, 2006, 7:08am UTC](https://forum.kirupa.com/t/gd-watermark-problem/186807/5 "2006-04-26T07:08:07Z")

</div>

> [@Ankou](#):
>
> According to teiz77 the following things were wrong (or not working):
> 
> The imagecopymerge thing is pretty clear. If you need more info, look at the PHP manual on that. It usually does a good job of explaining possible issues (especially in the comments).
> 
> The slashes. Well you were using “\” when it should have been “/” for the path to the images. And there was one case where you didn’t have the “/” to separate the path from the file name:
> 
> The “\” vs. “/” problem:
> 
> ```php
> $image = imagecreatefromjpeg($upl_dir . "\\" . $_GET['afbeelding']);
> 
> ```
> 
> The missing “/” - you needed this b/n $upl\_dir and $\_GET:
> 
> ```php
> $size = getimagesize($upl_dir . $_GET['afbeelding']);
> 
> ```
> 
> (PHP code above is your code, the correction can be seen in teiz77’s code)
> 
> BTW - teiz77, I didn’t mean to jump in on your post here and “take over” but I figured I’d explain it incase sWo0p came back for an answer before you could reply. I hope that was okay (and I hope I didn’t miss anything).

I couldn’t have said it better :thumb:
