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
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.