/    Sign up×
Community /Pin to ProfileBookmark

watermarking image.

I wrote a script this morning that watermarks JPG images that are uploaded using the [URL=http://us3.php.net/imagecopymerge]imagecopymerge[/URL] function. The watermark image is a PNG file created in Fireworks that has a transparent background color. The watermark is working, but the background is not a true transparent background, I have the int pct at 30 and it still showing up where I can see the watermark image as a square box. Here is part of my code

[code=php]
$watermark = imagecreatefrompng(‘ActIllWatermark.png’);
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image_h = imagecreatefromjpeg($imagename);
$size_x = imagesx($image_h);
$size_y = imagesy($image_h);
if($watermark_height > $size_y)
{
//Watermark is taller then image. lets scale it down to about 60%
$watermark_height_temp = $size_y * 0.6;
$diff = $watermark_height / $watermark_height_temp;
$watermark_height = $watermark_height_temp;
$watermark_width = $watermark_width / $diff;
}
if($watermark_width > $size_x)
{
$watermark_width_temp = $size_x * 0.6;
$diff = $watermark_width / $watermark_width_temp;
$watermark_width = $watermark_width_temp;
$watermark_height = $watermark_height / $diff;
}
$dest_x = ($size_x / 2) – ($watermark_width / 2);
$dest_y = ($size_y / 2) – ($watermark_height / 2);
imagecopymerge($image_h, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 30);
imagejpeg($image_h, $imagename);
[/code]

Attached is an example of what the image is looking like after I watermark it, the character should be all 1 color black.

Thanks for any help.

[upl-file uuid=be9c1454-436b-4201-9ef1-d463f3f0a12f size=16kB]ac383ca0a.jpg[/upl-file]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@bokehJul 18.2006 — If you are copying a PNG with single channel transparency onto a jpeg use [I]imagecopy()[/I]. For more info follow the link in my signature.
×

Success!

Help @cafrow spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...