A quick easy and dirty way to watermark CPG 1.4.x with out over writing any file A quick easy and dirty way to watermark CPG 1.4.x with out over writing any file
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

A quick easy and dirty way to watermark CPG 1.4.x with out over writing any file

Started by adamluz, September 08, 2008, 10:57:16 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

adamluz

Ok I can not figure out how to create a new topic so someone will need to split this on its own. Here is a quick easy and dirty way to watermark CPG 1.4.x with out over writing any files.

Create watermark.php in the root


<?php

    $imagesource 
=  $_GET['path'];
    
$watermarkPath 'watermark.png'// Set name of watermark CHANGE THIS TO THE NAME OF YOUR WATERMARK
    
$filetype substr($imagesource,strlen($imagesource)-4,4);
    
$filetype strtolower($filetype);
    
$watermarkType substr($watermarkPath,strlen($watermarkPath)-4,4);
    
$watermarkType strtolower($watermarkType);
    
    if(
$filetype == ".gif")  
        
$image = @imagecreatefromgif($imagesource);
    else  
        if(
$filetype == ".jpg" || $filetype == "jpeg")  
            
$image = @imagecreatefromjpeg($imagesource);
        else
            if(
$filetype == ".png")  
                
$image = @imagecreatefrompng($imagesource);
            else
                die();  
    
    if(!
$image)
        die();
    
    if(
$watermarkType == ".gif")
        
$watermark = @imagecreatefromgif($watermarkPath);
    else
        if(
$watermarkType == ".png")
            
$watermark = @imagecreatefrompng($watermarkPath);
        else
            die();
        
    if(!
$watermark)
        die();
        
    
$imagewidth imagesx($image);
    
$imageheight imagesy($image);  
    
$watermarkwidth =  imagesx($watermark);
    
$watermarkheight =  imagesy($watermark);
    
$startwidth = (($imagewidth $watermarkwidth) - 20);
    
$startheight = (($imageheight $watermarkheight) - 20);
    
imagecopy($image$watermark,  $startwidth$startheight00$watermarkwidth$watermarkheight);
    
imagejpeg($image);
    
imagedestroy($image);
    
imagedestroy($watermark);
?>




Modify includes/themes.inc.php

Find:

              <?php     echo  '<a href="javascript: window.close()"><img src="'


Change to


              <?php     echo  '<a href="javascript: window.close()"><img src="watermark.php?path=


Find


    if ($mime_content['content']=='image') {
        if (isset($image_size['reduced'])) {
            $winsizeX = $CURRENT_PIC_DATA['pwidth']+5;  //the +'s are the mysterious FF and IE paddings
            $winsizeY = $CURRENT_PIC_DATA['pheight']+3; //the +'s are the mysterious FF and IE paddings
            $pic_html = "<a href=\"javascript:;\" onclick=\"MM_openBrWindow('displayimage.php?pid=$pid&amp;fullsize=1','" . uniqid(rand()) . "','scrollbars=yes,toolbar=no,status=no,resizable=yes,width=$winsizeX,height=$winsizeY')\">";
            $pic_title = $lang_display_image_php['view_fs'] . "\n==============\n" . $pic_title;
            $pic_html .= "<img src=\"" . $picture_url . "\" class=\"image\" border=\"0\" alt=\"{$lang_display_image_php['view_fs']}\" /><br />";
            $pic_html .= "</a>\n";
        } else {
            $pic_html = "<img src=\"" . $picture_url . "\" {$image_size['geom']} class=\"image\" border=\"0\" alt=\"\" /><br />\n";
        }



Replace with:


    if ($mime_content['content']=='image') {
        if (isset($image_size['reduced'])) {
            $winsizeX = $CURRENT_PIC_DATA['pwidth']+5;  //the +'s are the mysterious FF and IE paddings
            $winsizeY = $CURRENT_PIC_DATA['pheight']+3; //the +'s are the mysterious FF and IE paddings
            $pic_html = "<a href=\"javascript:;\" onclick=\"MM_openBrWindow('displayimage.php?pid=$pid&amp;fullsize=1','" . uniqid(rand()) . "','scrollbars=yes,toolbar=no,status=no,resizable=yes,width=$winsizeX,height=$winsizeY')\">";
            $pic_title = $lang_display_image_php['view_fs'] . "\n==============\n" . $pic_title;
            $pic_html .= "<img src=\"watermark.php?path=" . $picture_url . "\" class=\"image\" border=\"0\" alt=\"{$lang_display_image_php['view_fs']}\" /><br />";
            $pic_html .= "</a>\n";
        } else {
            $pic_html = "<img src=\"watermark.php?path=" . $picture_url . "\" {$image_size['geom']} class=\"image\" border=\"0\" alt=\"\" /><br />\n";
        }


Thats it.

Upload watermark.png to root dir

Nibbler

Thanks for your contribution, but this 'on the fly' watermarking is only suitable for very low traffic websites. It doesn't stop people getting at the originals either.