watermark....tweak..

Third Party Plugins to CMSimple - how to install, use and create plugins

Moderator: Tata

Post Reply
twc
Posts: 233
Joined: Fri Jun 18, 2010 12:25 am
Location: Netherlands

watermark....tweak..

Post by twc » Sat Feb 11, 2017 11:01 pm

i try tweak it :oops: :roll: .......

wanna change the place of the watermark at the bottom :(

Code: Select all

<FilesMatch "\.(gif|jpg|jpeg)$"> 
   RewriteEngine On 
   RewriteCond %{REQUEST_FILENAME} -f 
   RewriteRule ^(.*)$ /watermark.php [T=application/x-httpd-php,L,QSA] 
</FilesMatch>

Code: Select all

<?php
waterMark($_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI']);
function waterMark($original)
{
	$original = urldecode($original);
	$info_o = @getImageSize($original);
	if (!$info_o)
		return false;
	$info_w = @getImageSize('watermark.png');
	if (!$info_w)
		return false;

	header("Content-Type: ".$info_o['mime']);

	$original = @imageCreateFromString(file_get_contents($original));
	$watermark = @imagecreatefrompng("watermark.png");
	$out = imageCreateTrueColor($info_o[0],$info_o[1]);

	imageCopyMerge($out, $original, 0, 0, 0, 0, $info_o[0], $info_o[1], 100);
	// The watermark is imposed only on the image to 250 pixels vertically and horizontally.
	if( ($info_o[0] > 50) && ($info_o[1] > 50) )
	{
		// For images without alpha channel
		// The last parameter of a function - the opacity of the watermark.
		imageCopyMerge($out, $watermark, ($info_o[0]-$info_w[0])/2, ($info_o[1]-$info_w[1])/2, 0, 0, $info_w[0], $info_w[1], 4);

		// For images with alpha channel
		// In this case the transparency are adjustable by the alpha channel of image
		// imageCopy($out, $watermark, ($info_o[0]-$info_w[0])/2, ($info_o[1]-$info_w[1])/2, 0, 0, $info_w[0], $info_w[1]);
	}

	switch ($info_o[2])
	{
	case 1:
		imageGIF($out);
		break;
	case 2:
		imageJPEG($out);
		break;
	case 3:
		imagePNG($out);
		break;
	default:
		return false;
	}

	imageDestroy($out); 
	imageDestroy($original); 
	imageDestroy($watermark); 

	return true; 
} 

?>
Last edited by twc on Sun Feb 12, 2017 2:58 pm, edited 1 time in total.

cmb
Posts: 13272
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: watermark....tweak..

Post by cmb » Sat Feb 11, 2017 11:57 pm

twc wrote:wanna change the place of the watermark at the bottom
Replace the following line:

Code: Select all

      imageCopyMerge($out, $watermark, ($info_o[0]-$info_w[0])/2, ($info_o[1]-$info_w[1])/2, 0, 0, $info_w[0], $info_w[1], 4);
with this:

Code: Select all

      imageCopyMerge($out, $watermark, ($info_o[0]-$info_w[0])/2, $info_o[1]-$info_w[1], 0, 0, $info_w[0], $info_w[1], 4);
(untested)
Christoph M. Becker – Plugins for CMSimple_XH

twc
Posts: 233
Joined: Fri Jun 18, 2010 12:25 am
Location: Netherlands

Re: watermark....tweak..

Post by twc » Sun Feb 12, 2017 8:10 am

cmb wrote:
twc wrote:wanna change the place of the watermark at the bottom
Replace the following line:

Code: Select all

      imageCopyMerge($out, $watermark, ($info_o[0]-$info_w[0])/2, ($info_o[1]-$info_w[1])/2, 0, 0, $info_w[0], $info_w[1], 4); 
with this:

Code: Select all

      imageCopyMerge($out, $watermark, ($info_o[0]-$info_w[0])/2, $info_o[1]-$info_w[1], 0, 0, $info_w[0], $info_w[1], 4); 
(untested)
omg thats it :shock: :mrgreen: thanks.....

where can i find the config numbers on internet...

cmb
Posts: 13272
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: watermark....tweak..

Post by cmb » Sun Feb 12, 2017 11:54 am

twc wrote:where can i find the config numbers on internet...
See http://php.net/manual/en/function.imagecopymerge.php.
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply