1
Zap_English
Watermark Hack for Xoops Core Imagemanager

Does anyone have this hack? The authors site seems to be dead

XOOPS Version XOOPS 2.5.8.1
PHP Version 7.0.32
mySQL Version 5.5.60-MariaDB

2
luciorota
Re: Watermark Hack for Xoops Core Imagemanager
  • 2019/1/3 10:24

  • luciorota

  • Module Developer

  • Posts: 216

  • Since: 2007/4/20


Hi
tell us more please

3
blindman
Re: Watermark Hack for Xoops Core Imagemanager
  • 2019/1/3 15:49

  • blindman

  • Not too shy to talk

  • Posts: 119

  • Since: 2005/6/26


Some years ago I made something similar using :
At that time it worked.
///### script for the file that manage some items that use watermark image ## ///
$storedir '....'// url for file store folder
$storepath '....'// path for file store folder
$moddir 'yourModuleDirName';
if(isset(
$_POST['xoops_upload_file'])) {

    
$fldname $_FILES[$_POST['xoops_upload_file'][0]];
    
$fldname = (get_magic_quotes_gpc()) ? stripslashes($fldname['name']) : $fldname['name'];
    
$ext xoops_getExtension($fldname); // some function to read extension
    
if(xoops_trim($fldname)!='') { // // some function to trim string
        
$uploader = new XoopsMediaUploader($storepath$allowed_mimetypes$maxfilesize$maxfilewidth$maxfileheight);
        do
            
$newname xoops_makeRname(8'prefix_').".".$ext;// some function to make a random based file name
        
while (file_exists($storedir.'/'.$newname));
        
        
$uploader->setTargetFileName($newname);
        if (
$uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
            if (
$uploader->upload()) {
                
$msg 'File upload success<br />';
                
$success.= 'File name: '.$uploader->getSavedFileName().'<br />';
                
$success.= 'File path: '.$uploader->getSavedDestination();
                
// some code here to set the new name
                // make thumb
                
xoops_ImageResize$storepath."/".$newname$storepath."/thumbs/".$newname$xoopsModuleConfig['thumbw'], $xoopsModuleConfig['thumbh']);
                
// resize image
                
$imgwidth $xoopsModuleConfig['maximgwidth'];
                
$imgheight $xoopsModuleConfig['maximgheight'];
                
xoops_ImageResize$storepath."/".$newname$storepath."/".$newname$imgwidth$imgheight);
                
// build watermark image
                
$watermark XOOPS_ROOT_PATH."/modules/".$moddir."/images/watermark.png";
                
xoops_ImageWatermark$storepath."/".$newname$watermark"jpeg""center""center");
                
// .... code about data to be saved
            
}
            
// .... code about data to be saved
        
}
        
// .... code about data to be saved
    
}
    
// .... code about data to be saved
}
///### functions used above ## ///
function myModule_ImageWatermark$original$watermark$save_as="jpeg"$h_position="center"$v_position="center"){
    global 
$moddir$xoopsModuleConfig;
    
//$target = XOOPS_ROOT_PATH."/modules/".$moddir."/images/watermark/target.jpg";
    
$target $original;
    
$wm_size '1';
    
$wmTarget XOOPS_ROOT_PATH."/modules/".$moddir."/uploads/png_trans.tmp";
    
$disp_width_max 150;                    // used when displaying watermark choices
    
$disp_height_max 80;                    // used when displaying watermark choices
    
$edgePadding 15;                        // used when placing the watermark near an edge
    
$quality 100;                           // used when generating the final image
    
    
$origInfo getimagesize($original); 
    
$origWidth $origInfo[0]; 
    
$origHeight $origInfo[1]; 
    
$waterMarkInfo getimagesize($watermark);
    
$waterMarkWidth $waterMarkInfo[0];
    
$waterMarkHeight $waterMarkInfo[1];

    if(
$wm_size=='larger'){
        
$placementX 0;
        
$placementY 0;
        
$h_position 'center';
        
$v_position 'center';
        
$waterMarkDestWidth $waterMarkWidth;
        
$waterMarkDestHeight $waterMarkHeight;
        if(
$waterMarkWidth $origWidth*1.05 && $waterMarkHeight $origHeight*1.05){
            
$wdiff $waterMarkDestWidth $origWidth;
            
$hdiff $waterMarkDestHeight $origHeight;
            
$sizer = ($wdiff $hdiff) ? (($wdiff/$waterMarkDestWidth)-0.05) : (($hdiff/$waterMarkDestHeight)-0.05) ;
            
$waterMarkDestWidth -= $waterMarkDestWidth $sizer;
            
$waterMarkDestHeight -= $waterMarkDestHeight $sizer;
        }
        else{
            
$wdiff $origWidth $waterMarkDestWidth;
            
$hdiff $origHeight $waterMarkDestHeight;
            
$sizer = ($wdiff $hdiff) ? (($wdiff/$waterMarkDestWidth)+0.05) : (($hdiff/$waterMarkDestHeight)+0.05);
            
$waterMarkDestWidth += $waterMarkDestWidth $sizer;
            
$waterMarkDestHeight += $waterMarkDestHeight $sizer;
        }
    }
    else{
        
$waterMarkDestWidth round($origWidth floatval($wm_size));
        
$waterMarkDestHeight round($origHeight floatval($wm_size));
        if(
$wm_size==1){
            
$waterMarkDestWidth -= 2*$edgePadding;
            
$waterMarkDestHeight -= 2*$edgePadding;
        }
    }
    
myModule_resizePngImage$watermark$waterMarkDestWidth$waterMarkDestHeight$wmTarget); // make resized png
    
    
$wmInfo getimagesize($wmTarget);
    
$waterMarkDestWidth $wmInfo[0];
    
$waterMarkDestHeight $wmInfo[1];
    
    
$differenceX $origWidth $waterMarkDestWidth;
    
$differenceY $origHeight $waterMarkDestHeight;
    
    switch(
$h_position){
        case 
'left':
            
$placementX $edgePadding;
            break;
        case 
'center':
            
$placementX =  round($differenceX 2);
            break;
        case 
'right':
            
$placementX $origWidth $waterMarkDestWidth $edgePadding;
            break;
    }
    switch(
$v_position){
        case 
'top':
            
$placementY $edgePadding;
            break;
        case 
'center':
            
$placementY =  round($differenceY 2);
            break;
        case 
'bottom':
            
$placementY $origHeight $waterMarkDestHeight $edgePadding;
            break;
    }
    
$resultImage = ($origInfo[2]==3) ?imagecreatefrompng($original) :  imagecreatefromjpeg($original);
    
imagealphablending($resultImageTRUE);
    
    
$finalWaterMarkImage imagecreatefrompng($wmTarget);
    
$finalWaterMarkWidth imagesx($finalWaterMarkImage);
    
$finalWaterMarkHeight imagesy($finalWaterMarkImage);
    
    
imagecopy$resultImage$finalWaterMarkImage$placementX$placementY00$finalWaterMarkWidth$finalWaterMarkHeight);
    
    if(
$origInfo[2]==3){
        
imagealphablending$resultImageFALSE);
        
imagesavealpha$resultImageTRUE);
        
imagepng$resultImage$target$quality);
    }else{
        
imagejpeg$resultImage$target$quality); 
    }
    
    
imagedestroy($resultImage);
    
imagedestroy($finalWaterMarkImage);
    
unlink($wmTarget);

}
function 
xoops_resizePngImage$img$newWidth$newHeight$target){
    
$srcImage imagecreatefrompng$img );
    if(
$srcImage == ''){
        return 
FALSE;
    }
    
$srcWidth imagesx($srcImage);
    
$srcHeight imagesy($srcImage);
    
$percentage = (double)$newWidth/$srcWidth;
    
$destHeight round($srcHeight*$percentage)+1;
    
$destWidth round($srcWidth*$percentage)+1;
    if(
$destHeight $newHeight){
        
// if the width produces a height bigger than we want, calculate based on height
        
$percentage = (double)$newHeight/$srcHeight;
        
$destHeight round($srcHeight*$percentage)+1;
        
$destWidth round($srcWidth*$percentage)+1;
    }
    
$destImage imagecreatetruecolor($destWidth-1,$destHeight-1);
    if(!
imagealphablending($destImage,FALSE)){
        return 
FALSE;
    }
    if(!
imagesavealpha$destImageTRUE)){
        return 
FALSE;
    }
    if(!
imagecopyresampled$destImage$srcImage0000$destWidth$destHeight$srcWidth$srcHeight)){
        return 
FALSE;
    }
    if(!
imagepng($destImage,$target)){
        return 
FALSE;
    }
    
imagedestroy($destImage);
    
imagedestroy($srcImage);
    return 
TRUE;
}

Hope it helps.

4
Zap_English
Re: Watermark Hack for Xoops Core Imagemanager

where did you insert the code?

5
blindman
Re: Watermark Hack for Xoops Core Imagemanager
  • 2019/1/4 17:47

  • blindman

  • Not too shy to talk

  • Posts: 119

  • Since: 2005/6/26


This wasn't a core modification. Was part of c custom module admin page for publishing article like stuff.
Into a page where you can add/edit/save/delete items we usually have a form for add/edit options, save if $op=='save', for example. There we can collect $_POST values from the form and save them in DB.
Well, there were the part with:
if(isset($_POST['xoops_upload_file'])) {

inside this loop I was using those functions.
The functions you can put into some function.php file that is always included.

Login

Who's Online

221 user(s) are online (155 user(s) are browsing Support Forums)


Members: 0


Guests: 221


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits