I wrote a script this morning that watermarks JPG images that are uploaded using the imagecopymerge 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
Attached is an example of what the image is looking like after I watermark it, the character should be all 1 color black.PHP Code:$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);
Thanks for any help.


Reply With Quote
Bookmarks