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
';
$success.= 'File name: '.$uploader->getSavedFileName().'
';
$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($resultImage, TRUE);
$finalWaterMarkImage = imagecreatefrompng($wmTarget);
$finalWaterMarkWidth = imagesx($finalWaterMarkImage);
$finalWaterMarkHeight = imagesy($finalWaterMarkImage);
imagecopy( $resultImage, $finalWaterMarkImage, $placementX, $placementY, 0, 0, $finalWaterMarkWidth, $finalWaterMarkHeight);
if($origInfo[2]==3){
imagealphablending( $resultImage, FALSE);
imagesavealpha( $resultImage, TRUE);
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( $destImage, TRUE)){
return FALSE;
}
if(!imagecopyresampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight)){
return FALSE;
}
if(!imagepng($destImage,$target)){
return FALSE;
}
imagedestroy($destImage);
imagedestroy($srcImage);
return TRUE;
}
Hope it helps.