Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: A quick easy and dirty way to watermark CPG 1.4.x with out over writing any file  (Read 10986 times)

0 Members and 1 Guest are viewing this topic.

adamluz

  • Contributor
  • Coppermine newbie
  • ***
  • Offline Offline
  • Posts: 1

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
Code: [Select]

<?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:
Code: [Select]
              <?php     echo  '<a href="javascript: window.close()"><img src="'

Change to

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

Find

Code: [Select]
    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:

Code: [Select]
    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
« Last Edit: September 08, 2008, 11:04:20 pm by Nibbler »
Logged

Nibbler

  • Guest

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.
Logged
Pages: [1]   Go Up
 

Page created in 0.025 seconds with 20 queries.