Código PHP:
   <? function watermark($SourceFile?, $WatermarkFile?, $SaveToFile? = NULL) 
 
{ 
 
$watermark = @imagecreatefrompng($WatermarkFile?) 
or exit('Cannot open the watermark file.'); 
imageAlphaBlending($watermark, false); 
imageSaveAlpha($watermark, true); 
$image_string = @file_get_contents($SourceFile?) 
or exit('Cannot open image file.'); 
$image = @imagecreatefromstring($image_string) 
or exit('Not a valid image format.'); 
$imageWidth=imageSX($image); 
$imageHeight=imageSY($image); 
$watermarkWidth=imageSX($watermark); 
$watermarkHeight=imageSY($watermark); 
$coordinate_X = ( $imageWidth - 5) - ( $watermarkWidth); 
$coordinate_Y = ( $imageHeight - 5) - ( $watermarkHeight); 
imagecopy($image, $watermark, $coordinate_X, $coordinate_Y, 
0, 0, $watermarkWidth, $watermarkHeight); 
if(!($SaveToFile?)) header('Content-Type: image/jpeg'); 
imagejpeg ($image, $SaveToFile?, 100); 
imagedestroy($image); 
imagedestroy($watermark); 
if(!($SaveToFile?)) exit; 
} 
 
And after 
 
$result = file_put_contents( $filename, file_get_contents('php://input') ); if (!$result) { 
 
print "ERROR: Failed to write data to $filename, check permissions\n"; 
exit(); } 
This code: 
 
// The image should be located in a non public directory 
 
$image_location = 'dir/test.jpg'; 
 
// Locate the watermark file wherever you choose (remember PNG format) 
 
$watermark_location = 'watermark.png'; 
 
// Watermark the image and send it to the browser 
 
watermark($image_location, $watermark_location, $image_location);    
 

