Jump to content

GD watermark problem


Brian W

Recommended Posts

This is probably a simple issue, but can't seem to figure it out...

When I watermark the image, everything is fine besides the transparency on the watermark is black rather than clear.

<?php
function ratio($x, $y, $max){
if($x > $y){
	if($x > $max){
		$y = round(($y*$max)/$x);
		$x = $max;
	}
} else {
	if($y > $max){
		$x = round(($x*$max)/$y);
		$y = $max;
	}
}
return array($x, $y);
}
function upload_image($img){
global $time;
$time = time();
if(!isset($img['type'])){
	return "ERROR: invalid image upload";
}
if($img['type'] != "image/jpg" && $img['type'] != "image/jpeg" && $img['type'] != "image/pjpeg"){ 
	return "ERROR: file must be a JPEG or JPG.".$img['type'];
}
$src = $img['tmp_name'];//Temp File
$temp = imagecreatefromjpeg($src) or die("ERRO on temp");
list($ox, $oy) = getimagesize($src);
$large_max = 500;
$small_max = 160;
list($lx, $ly) = ratio($ox, $oy, $large_max);
list($sx, $sy) = ratio($ox, $oy, $small_max);
list($wx, $wy) = ratio(400, 80, $lx);
$wpx = round($lx - $wx)/2; $wpy = round($ly - $wy)/2; // Watermark XY Positions
//die((string)$wpy);
$water_mark_src = imagecreatefrompng(ROOT."\\uploads\\watermark.png");
$water_mark = imagecreatetruecolor($wx, $wy);
	imagecopyresampled($water_mark, $water_mark_src, 0, 0, 0, 0, $wx, $wy, 400, 80);

$large = imagecreatetruecolor($lx, $ly);
	imagecopyresampled($large, $temp, 0, 0, 0, 0, $lx, $ly, $ox, $oy);
	imagecopymerge($large, $water_mark, $wpx, $wpy, 0, 0, $wx, $wy, 20) or die("here");//Overlay Watermark
	imagejpeg($large, ROOT."\\uploads\\large\\".$time.".jpg", 100);
$small = imagecreatetruecolor($sx, $sy);
	imagecopyresampled($small, $temp, 0, 0, 0, 0, $sx, $sy, $ox, $oy);
	imagejpeg($small, ROOT."\\uploads\\small\\".$time.".jpg", 100);
//return "$wx $wy";
return true;
}
?>

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/164140-gd-watermark-problem/
Share on other sites

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.