BlaPageBlaPage
It's about Internet – SEO, Black Hat SEO, Wordpress, Personal Computers, Technology, WebHosting

Add watermark to Mihalism Image Hosting Script Images

So, I’ve jumped on the Image Hosting bus and one of the things that was bothering me about the MMH script was that uploaders could just link straight to the pics and I’d get no credit for my “generousity”…
Looked around the web and have seen a couple of posts about adding a watermark to all the uploaded images… somebody even dug up the code that worked in the previous version, but didn’t with the new version (5.0.2)…So, I’m not going to take any credit for the code, just for finding the right place to put it.

Anyway, follow these steps and you should be good to go..
Open “upload.php” and search for this –

$mmhclass->image->create_thumbnail($filename);

Should be line 53 for those following along in their hymnals…
After that line, copy and paste this into the file –

$path = "images/";
$mmhclass->image->add_watermark($extension, $path, $filename);

Save the file…

Now go into the “source\includes\” folder and open “imagemagick.php”.
Goto the end of the file and go back up inside the first curly bracket (“}”) and paste this into the file –

//New function to Add Watermark
		function add_watermark($extension, $path, $filename)
		{
			global $mmhclass;
			$image_upfile = $path.$filename;
		
			if($extension == "jpeg" || $extension == "jpg")
			{
				$watermark = imagecreatefrompng('css/watermark.png'); 
				imageAlphaBlending($watermark, false);
				imageSaveAlpha($watermark, true); 
				$watermark_width = imagesx($watermark);  
				$watermark_height = imagesy($watermark);  
				$image = imagecreatetruecolor($watermark_width, $watermark_height);  
				$image = imagecreatefromjpeg($image_upfile);  
				$size = getimagesize($image_upfile);  
				$dest_x = $size[0] - $watermark_width - 5;  
				$dest_y = $size[1] - $watermark_height - 5;  
				imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
		
				if(@imagejpeg($image, $image_upfile, 90))
				{
					$img_watermakred = "yes";
				}
		
				imagedestroy($image);
				imagedestroy($watermark);
			}
		
			if($extension == "png")
			{
				$watermark = imagecreatefrompng('css/watermark.png');  
				$watermark_width = imagesx($watermark);  
				$watermark_height = imagesy($watermark);  
				$image = imagecreatetruecolor($watermark_width, $watermark_height);  
				$image = imagecreatefrompng($image_upfile);  
				$size = getimagesize($image_upfile);  
				$dest_x = $size[0] - $watermark_width - 5;  
				$dest_y = $size[1] - $watermark_height - 5;  
				imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
		
				if(@imagepng($image, $image_upfile))
				{
					$img_watermakred = "yes";
				}
		
				imagedestroy($image);
				imagedestroy($watermark);
			}
		
			if($extension == "gif")
			{
				$watermark = imagecreatefrompng('css/watermark.png');  
				$watermark_width = imagesx($watermark);  
				$watermark_height = imagesy($watermark);  
				$image = imagecreatetruecolor($watermark_width, $watermark_height);  
				$image = imagecreatefromgif($image_upfile);  
				$size = getimagesize($image_upfile);  
				$dest_x = $size[0] - $watermark_width - 5;  
				$dest_y = $size[1] - $watermark_height - 5;  
				imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);  
		
				if(@imagegif($image, $image_upfile))
				{
					$img_watermakred = "yes";
				}
		
				imagedestroy($image);
				imagedestroy($watermark);
			}
		}

Save the file…

Finally, create a png file of whatever you want your watermark to be, save it as “watermark.png” and put it in the root “css” folder. If you want to name it something different or put it somewhere else, just search in the code above for “css/watermark.png” and replace it…

Now all the new photos that are uploaded will be marked with your watermark…

If you haven’t understood where to put the last code in “imagemagick.php”
Then it before these closing php code

      }
?>

Hope this BlaPage was helpful, Add watermark to Mihalism Image Hosting Script Images.


Link To This BlaPage From Your Website :

Category: Php, Scripts, Webmaster Tips and Tools

Tagged: , , , , ,

Comments are closed.

Facebook FanPage

Follow BlaPage on Twitter