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] Link to comment https://forums.phpfreaks.com/topic/101459-solved-watermark-showing-as-a-block/ 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"); Link to comment https://forums.phpfreaks.com/topic/101459-solved-watermark-showing-as-a-block/#findComment-519024 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? Link to comment https://forums.phpfreaks.com/topic/101459-solved-watermark-showing-as-a-block/#findComment-520770 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 Link to comment https://forums.phpfreaks.com/topic/101459-solved-watermark-showing-as-a-block/#findComment-520775 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 Link to comment https://forums.phpfreaks.com/topic/101459-solved-watermark-showing-as-a-block/#findComment-520781 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... Link to comment https://forums.phpfreaks.com/topic/101459-solved-watermark-showing-as-a-block/#findComment-520785 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 Link to comment https://forums.phpfreaks.com/topic/101459-solved-watermark-showing-as-a-block/#findComment-520786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.