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

Link to comment
Share on other sites

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

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.