Jump to content

[SOLVED] Issue with watermarking


Brian W

Recommended Posts

I can't seem to figure out why this code won't overlay my watermark.png file over the image.

$target_path = "images/";
$name = date("ymd").basename($_FILES['uploadedfile']['name']);
$target_path = $target_path . $name;

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
$o['name'] = $target_path;
list($o['width'], $o['height']) = getimagesize($o['name']);
if($o['width'] > $o['height']){
$n['width'] = 400;
$n['height'] = round(($o['height']/$o['width'])*400);
} else {
$n['height'] = 400;
$n['width'] = round(($o['width']/$o['height'])*400);
}
$src = imagecreatefromjpeg($o['name']);//Create Handle

$watermark = imagecreatefrompng('watermark.png');

$tmp=imagecreatetruecolor($n['width'],$n['height']);
imagecopyresampled($tmp,$src,0,0,0,0,$n['width'],$n['height'],$o['width'],$o['height']);
imagecopy($tmp, $watermark, 0, 0, 0, 0, 400, 400);

imagejpeg($tmp,$o['name'],100);//Output

I found one person somewhere that said something about the version of the GD library they got (packaged with RedHat) had a bug in imagecopy(), but I'm thinking I'm just f'ing up.

Link to comment
https://forums.phpfreaks.com/topic/160819-solved-issue-with-watermarking/
Share on other sites

I've never used the PHP image functions to do such a thing, so I know nuts about them.

 

But maybe one of these will help you:

http://www.google.com/search?rlz=1C1GGLS_enUS330US330&sourceid=chrome&ie=UTF-8&q=php+add+a+png+watermark

Fair enough.  You'd be surprised though how many people ask for help without making a solid attempt on their own though.

 

The next step would be to try and get more information as to why it's failing.  Turn on error reporting if it's not already.  See if those image*() functions have a way of returning extended error information and check that information at every step of the way.

 

And double check your version of any extension you're using for known bugs and / or problems.

 

If all else fails, upload or send me a copy of your png and if I have time I can try to run it on my machine.

Excuse me while I kick myself... this entire time there hasn't been any issue whatsoever besides me overwriting the incorrect file (wrong directory on in the ftp!). What tipped me off was setting error_reporting to E_ALL and not receiving any errors whatsoever.

Thanks for your help, sorry I inconvenienced you and any one else who looked at this topic.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.