1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Mihalism Watermark Code

Discussion in 'Making Money' started by nesterdwarf, Sep 9, 2008.

  1. nesterdwarf

    nesterdwarf Regular Member

    Joined:
    May 30, 2008
    Messages:
    276
    Likes Received:
    539
    Location:
    State of Misery...er, Missouri...
    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 (4.0.2)...

    So, I'm not going to take any credit for the code, just for finding the right place to put it :p

    Anyway, follow these steps and you should be good to go...

    Open "upload.php" and search for this -
    Code:
    $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 -
    Code:
    $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 -
    Code:
    //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 that helped, click the button...

    ND
     
    • Thanks Thanks x 2
  2. venn

    venn Junior Member

    Joined:
    Aug 19, 2008
    Messages:
    145
    Likes Received:
    25
    errr.... i didnt understand the last code placement.... Goto the end of the file and go back up?
     
  3. nesterdwarf

    nesterdwarf Regular Member

    Joined:
    May 30, 2008
    Messages:
    276
    Likes Received:
    539
    Location:
    State of Misery...er, Missouri...
    Yeah, guess that could have been clearer...you want to include it in the class "mmhclass_image_functions" below all the other standard functions...

    ND
     
  4. Top25

    Top25 Registered Member

    Joined:
    Mar 15, 2008
    Messages:
    68
    Likes Received:
    2
    Nice mod that will increase traffic
     
  5. venn

    venn Junior Member

    Joined:
    Aug 19, 2008
    Messages:
    145
    Likes Received:
    25
    sorry.. im noob.... in what line exactly we have to put the last code?


    -NewBiE-
     
  6. nesterdwarf

    nesterdwarf Regular Member

    Joined:
    May 30, 2008
    Messages:
    276
    Likes Received:
    539
    Location:
    State of Misery...er, Missouri...
    Search for this -

    Code:
          }
    ?>
    
    Paste it in before that...that's it.

    ND
     
  7. venn

    venn Junior Member

    Joined:
    Aug 19, 2008
    Messages:
    145
    Likes Received:
    25
    how to make the watermark have transparent background?
     
  8. nesterdwarf

    nesterdwarf Regular Member

    Joined:
    May 30, 2008
    Messages:
    276
    Likes Received:
    539
    Location:
    State of Misery...er, Missouri...
    I knew that one would come up... I had to jack with it for awhile to get it to work... I'll try and explain it...

    You'll need to find a color that isn't in your overlay image and use that as your background color. For example, my overlay image was black and white, so I used red as my background.

    Now, when you go to save the image, you'll need to use something like Photoshop "Save for the Web..." In that dialog box, you can select the color that you want to be transparent (red, for example) and then save the image as a png file...

    Not the greatest explaination, but if you need a better one, you can search "setting the transparency index in a png" and find alot better examples.

    ND
     
  9. ted_walker

    ted_walker Newbie

    Joined:
    Oct 23, 2008
    Messages:
    12
    Likes Received:
    3
    This is what I've been looking for so long. Works great. Many thanks
     
  10. IamTURK

    IamTURK Regular Member

    Joined:
    Jun 5, 2009
    Messages:
    225
    Likes Received:
    17
    Location:
    Turkey
    its not working for me...
     
  11. Mr.Whitehat

    Mr.Whitehat Senior Member

    Joined:
    Apr 23, 2009
    Messages:
    855
    Likes Received:
    220
    Occupation:
    Wandering Around !
    Location:
    Dating Moolah Babe^
    Well, this is already posted in mihalism support forum.isnt it? bw have any other mod to share?
     
  12. hamlid

    hamlid Newbie

    Joined:
    Mar 8, 2008
    Messages:
    6
    Likes Received:
    0
    i also did that once, but my approach was with htaccess