Jump to content

[SOLVED] Watermark showing as a block


rondog

Recommended Posts

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

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");

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?  :D

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.