Page 1 of 1

PHP WaterMark

Posted: Fri Oct 22, 2004 9:55 pm
by xeroinsanity89
How do I add this:

Code: Select all

<?php

// Load function
require("./phpWatermark.inc.php");

// Instantiate phpWatermark
// The only parameter currently required is the name
// of the image, which should get marked
$wm = new watermark("/path/to/image.png");

// Optionally specify the position of
// the watermark on the image
$wm->setPosition("RND");

// Optionally specify a fixed color for the text
$wm->setFixedColor("#FF00FF");
// or
$wm->setFixedColor(array(255, 0, 255));

// Add a watermark containing the string
// "phpWatermark" to the image specified above
$wm->addWatermark("phpWatermark", "TEXT");

// Fetch the marked image
$im = $wm->getMarkedImage();

// Output
header("Content-type: image/png");
imagepng($im);

?>

to the following so it will automatically add my watermark to the pictures being uploaded by the below code which is an upload script so that users and upload their pictures. I just want it to display the following text in the bottem right hand corner in a readable size but not huge in each picture, "www.xero.insanityhost.com" (without quotes). Can someone edit it and add it to the following code so it will work if possible? Im a PHP n00b. It took me long enough to figure out how to edit the code below.

Code: Select all

<br>
              <?php ?>
              <?php

require("fileupload-class.php");

#--------------------------------#
# Variables
#--------------------------------#

// The path to the directory where you want the 
// uploaded files to be saved. This MUST end with a 
// trailing slash unless you use $path = ""; to 
// upload to the current directory. Whatever directory
// you choose, please chmod 777 that directory.

	$path = "uploads/";

// The name of the file field in your form.

	$upload_file_name = "userfile";

// ACCEPT mode - if you only want to accept
// a certain type of file.
// possible file types that PHP recognizes includes:
//
// OPTIONS INCLUDE:
//  text/plain
//  image/gif
//  image/jpeg
//  image/png
	
	// Accept ONLY gifs's
	#$acceptable_file_types = "image/gifs";
	
	// Accept GIF and JPEG files
	$acceptable_file_types = "image/gif|image/jpeg|image/pjpeg";
	
	// Accept ALL files
	#$acceptable_file_types = "";

// If no extension is supplied, and the browser or PHP
// can not figure out what type of file it is, you can
// add a default extension - like ".jpg" or ".txt"

	$default_extension = "";

// MODE: if your are attempting to upload
// a file with the same name as another file in the
// $path directory
//
// OPTIONS:
//   1 = overwrite mode
//   2 = create new with incremental extention
//   3 = do nothing if exists, highest protection

	$mode = 2;
	
	
#--------------------------------#
# PHP
#--------------------------------#
	if (isset($_REQUEST['submitted'])) {
		/* 
			A simpler way of handling the submitted upload form
			might look like this:
			
			$my_uploader = new uploader('en'); // errors in English
	
			$my_uploader->max_filesize(30000);
			$my_uploader->max_image_size(800, 800);
			$my_uploader->upload('userfile', 'image/gif', '.gif');
			$my_uploader->save_file('uploads/', 2);
			
			if ($my_uploader->error) {
				print($my_uploader->error . "<br><br>\n");
			} else {
				print("Thanks for uploading " . $my_uploader->file['name'] . "<br><br>\n");
			}
		*/
			
		// Create a new instance of the class
		$my_uploader = new uploader($_POST['language']); // for error messages in french, try: uploader('fr');
		
		// OPTIONAL: set the max filesize of uploadable files in bytes
		$my_uploader->max_filesize(1048576);
		
		// OPTIONAL: if you're uploading images, you can set the max pixel dimensions 
		$my_uploader->max_image_size(1024, 768); // max_image_size($width, $height)
		
		// UPLOAD the file
		if ($my_uploader->upload($upload_file_name, $acceptable_file_types, $default_extension)) {
			$my_uploader->save_file($path, $mode);
		}
		
		if ($my_uploader->error) {
			echo $my_uploader->error . "<br><br>\n";
		
		} else {
			// Successful upload!
			print($my_uploader->file['name'] . " was successfully uploaded! <a href="" . $_SERVER['PHP_SELF'] . "">Try Again</a><br>");
			
			// Print all the array details...
			//print_r($my_uploader->file);
			
			// ...or print the file
			if(stristr($my_uploader->file['type'], "image")) {
				echo "<img src="" . $path . $my_uploader->file['name'] . "" border="0" alt="">";
			} else {
				$fp = fopen($path . $my_uploader->file['name'], "r");
				while(!feof($fp)) {
					$line = fgets($fp, 255);
					echo $line;
				}
				if ($fp) { fclose($fp); }
			}
 		}
 	}




#--------------------------------#
# HTML FORM
#--------------------------------#
?>
            </p>
            <form enctype="multipart/form-data" action="<?= $_SERVER['PHP_SELF']; ?>" method="POST">
                <input type="hidden" name="submitted" value="true">
                <span class="style4">Upload this file:</span><br>
                <input name="<?= $upload_file_name; ?>" type="file">
                <br>
                <br>
                <input type="submit" value="Upload File">

Posted: Fri Oct 22, 2004 10:17 pm
by kettle_drum

Code: Select all

// Add a watermark containing the string
// "phpWatermark" to the image specified above
$wm->addWatermark("phpWatermark", "TEXT");
Seems that you just have to change phpWatermark to whatever you want to be displayed. Keep it within the double quotes and you should have no troubles.

Then change the path to the file youve just uploaded.

Code: Select all

$wm = new watermark("/path/to/image.png");
You should get that from in the upload script.

Then add the code to the uploadt script at a point where the image has bene uploaded.

Posted: Fri Oct 22, 2004 10:22 pm
by xeroinsanity89
Ok cool, so i would just make it

Code: Select all

// Add a watermark containing the string// "phpWatermark" to the image specified above$wm->addWatermark

("phpWatermark", "www.xero.insanityhost.com");
Where would I add all the lines of php into the upload script, and does this mean that it will automatically add the text to all uploaded pictures that users upload?