Jump to content

PHP WaterMark Code Question


devain

Recommended Posts

Hello

I am currently working on some watermark code for a site everything works great as far as the code that I am going to post below my question is when l link to the image what I would like to do is when the person right clicks on the image I would like it to download the png overlay instead of the image and I am not sure how to accomplish this below is the code and How I pull the image and overlay from the file.

[code]

//session_start();

$db_host = '';
$db_user = '';
$db_pwd = '';
$db_name = '';
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());   


$res=mysql_query("select imageno, picture2 from image where id='$id'");
$data=mysql_result($res,0,"imageno");
$dir=mysql_result($res,0,"picture2");

//session_start();
header('content-type: image/jpeg');

$imagesource =  $dir;
$filetype = substr($imagesource,strlen($imagesource)-4,4);
$filetype = strtolower($filetype);
if($filetype == ".gif")  $image = @imagecreatefromgif($imagesource); 
if($filetype == ".jpg")  $image = @imagecreatefromjpeg($imagesource); 
if($filetype == ".png")  $image = @imagecreatefrompng($imagesource); 
if (!$image) die();
$watermark = @imagecreatefrompng('watermark.png');
$imagewidth = imagesx($image);
$imageheight = imagesy($image); 
$watermarkwidth =  imagesx($watermark);
$watermarkheight =  imagesy($watermark);
$startwidth = (($imagewidth - $watermarkwidth)/2);
$startheight = (($imageheight - $watermarkheight)/2);
imagecopy($image, $watermark,  $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
imagejpeg($image);
imagejpeg($image);
imagedestroy($watermark);
imagedestroy($image);

[code]


this is the image tag that pulls the image

<img src="http://www.domain.com/showp1.php?&id={id}"  >


any help would be appericated
[/code][/code]
Link to comment
https://forums.phpfreaks.com/topic/32760-php-watermark-code-question/
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.