rondog Posted April 16, 2008 Share Posted April 16, 2008 I am trying to watermark some images with a transparent PNG, but the PNG is showing up just as a block of white. See here -> http://dopserv1.com/hosted/army/l.php?p=12 Here is my code: <?php header("Content-type: image/jpeg"); include 'connect.php'; $picid = $_GET['p']; $sql = mysql_query("SELECT filename FROM photo WHERE id = '$picid'") or die(mysql_error()); $row = mysql_fetch_row($sql); $src = "photos/".$row[0]; $watermark = imagecreatefrompng("images/watermark.png"); $waterw = imagesx($watermark); $waterh = imagesy($watermark); $img = imagecreatetruecolor($waterw,$waterh); $img = imagecreatefromjpeg($src); $size = getimagesize($src); $dest_x = ($size[0]/2) - ($waterw/2); $dest_y = ($size[1]/2) - ($waterh/2); imagecopymerge($img,$watermark,$dest_x,$dest_y,0,0,$waterw,$waterh,50); imagejpeg($img); imagedestroy($img); imagedestroy($watermark); ?> I attached the PNG file just in case you want to see it [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
mrdamien Posted April 17, 2008 Share Posted April 17, 2008 I think the watermark also needs to be a truecolor image list($waterw, $waterh, $type, $attr) = getimagesize("images/watermark.png"); $watermark = imagecreatetruecolor($waterw, $waterh); $watermark = imagecreatefrompng("images/watermark.png"); Quote Link to comment Share on other sites More sharing options...
rondog Posted April 18, 2008 Author Share Posted April 18, 2008 Not sure if you meant to replace the code something like this: <?php header("Content-type: image/jpeg"); include 'connect.php'; $picid = $_GET['p']; $sql = mysql_query("SELECT filename FROM photo WHERE id = '$picid'") or die(mysql_error()); $row = mysql_fetch_row($sql); $src = "photos/".$row[0]; list($waterw, $waterh, $type, $attr) = getimagesize("images/watermark.png"); $watermark = imagecreatetruecolor($waterw, $waterh); $watermark = imagecreatefrompng("images/watermark.png"); $waterw = imagesx($watermark); $waterh = imagesy($watermark); $img = imagecreatetruecolor($waterw,$waterh); $img = imagecreatefromjpeg($src); $size = getimagesize($src); $dest_x = ($size[0]/2) - ($waterw/2); $dest_y = ($size[1]/2) - ($waterh/2); imagecopymerge($img,$watermark,$dest_x,$dest_y,0,0,$waterw,$waterh,50); imagejpeg($img); imagedestroy($img); imagedestroy($watermark); ?> but its still doing the same thing..got anything else? Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Share Posted April 18, 2008 I have had troubles in the past with browsers not being capable of displaying a transparent BG on a .png file. My solution was turning into a gif with the correct matting color. Hope this helps Quote Link to comment Share on other sites More sharing options...
rondog Posted April 18, 2008 Author Share Posted April 18, 2008 ok I made it a gif instead and that worked. GIF it is I suppose! thanks Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Share Posted April 18, 2008 I would like to take this opportunity to congradulate myself on finally helping some one solve a problem. Thank you, Thank you...please no applause... Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Share Posted April 18, 2008 Please take note: it had nothing to do with PHP Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.