Okay, I curently have a PHP upload script that works great. Only additional thing I wish it would do is add a watermark to each image on upload.
I have searched and searched and found a ton of watermarking snippets, but my problem is.... I just simply do not have the know-how to combine the two.
This is my upload script:
<?
error_reporting(E_ALL ^ E_NOTICE);
$maxsize="200"; // In KiloBytes, set to 0 for unlimited.
$randomname="1"; // Use random file names? 1=yes, 0=use original file name.
$usetypes="1"; // Leave this to 1 to restrict file types (Below), change to 0 to allow all file types.
$types=array("jpg","gif"); // Please keep structure.
$url="http://PhatServer.net/Jeepin/"; // Full url to where files are stored. With Trailing Slash
$folder=""; // Path to files folder. If this fails use full path below. With trailing slash
$fullpath="/usr/local/www/data-dist/Jeepin/"; // Only use this variable if you wish to use full server paths. Otherwise leave this empty! With trailing slash
$password=""; //Use this only if you want to password protect your uploads.
//Edit some design vars.
$textcolor="#000000";
$textface="Verdana, Arial, Helvetica, sans-serif";
$textsize="12px";
$pagebg="#CDCDCD";
$tablebg="#FFFFFF";
/* -====- Stop Editing -====- */
If($password) {
If($_POST['verify']) {
If($_POST['dopass']=="$password") {
$_SESSION['phUploader']="True";
}
}
}
?>
<html>
<head>
<title>Jeepin.com Image upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<style type="text/css">
body{background-color:<?Echo($pagebg);?>;}
a:link {color:<?Echo($textcolor);?>;}
a:visited {color:<?Echo($textcolor);?>;}
.text{font-face:<?Echo($textface);?>; font-size:<?Echo($textsize);?>; font-color:<?Echo($textcolor);?>;}
input{font-face:<?Echo($textface);?>; font-size:<?Echo($textsize);?>; font-color:<?Echo($textcolor);?>;}
</style>
<body background="http://jeepin.com/ubb/dirttan.gif">
<div align="center">
<p> </p>
<p>
<?
function copyright() {
global $pagebg;
Echo("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#000000\" width=\"400\" align=\"center\" bgcolor=\"$pagebg\" class=\"text\">\n");
Echo("<tr>\n");
Echo("<td align=\"right\">Powered by: <a href=\"http://www.phphq.net/?script=phUploader\" target=\"_blank\">phUploader v1.1</a></td>\n");
Echo("</tr>\n");
Echo("</table>\n");
Echo("</body>\n");
Echo("</html>\n");
}
If($password) {
If($_SESSION['phUploader']!="True") {
Echo("<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n");
Echo("<table border=\"1\" cellpadding=\"1\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#000000\" width=\"400\" align=\"center\" class=\"text\" bgcolor=\"".$tablebg."\">\n");
Echo("<tr>\n");
Echo("<td width=\"70%\">Enter Password:</td>\n");
Echo("<td width=\"30%\"><input type=\"password\" name=\"dopass\" /></td>\n");
Echo("<input type=\"hidden\" name=\"verify\" value=\"true\">\n");
Echo("<td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"verify\" value=\" Verify Password \" /></td>\n");
Echo("</tr>\n");
Echo("</table>\n");
Echo("</form>\n");
exit(copyright());
}
}
If($fullpath){$folder=$fullpath;}
If(!$fullpath) {
$folder2=str_replace(".","",str_replace("/","",$folder));
If(!is_dir($folder2)) {
Echo("<div align=\"center\" class=\"text\">The folder: <b>$folder2</b> does not exists. I am going to try and create it.</div><br />\n");
If(!@mkdir($folder2)) {
exit("<div align=\"center\" class=\"text\">Creating the directory <b>$folder2 failed</b>. Please do this manually.</div><br />\n");
} Else {
Echo("<div align=\"center\" class=\"text\">Directory created, now I am going to try and chmod the directory for you.</div><br />\n");
If(!@chmod($folder2,octdec("0777"))) {
exit("<div align=\"center\" class=\"text\">Folder chmod was not successful. Please use a ftp client or SSH to chmod the folder <b>$folder</b> 777</div><br />\n");
} Else {
Echo("<div align=\"center\" class=\"text\">Chmod was successful, please continue using this script.</div><br />\n");
}
}
}
}
If($_POST['doupload']) {
$file=$_FILES['file']['tmp_name'];
$size=$_FILES['file']['size'];
$type=$_FILES['file']['type'];
$name=strtolower($_FILES['file']['name']);
$ext=substr(strrchr($name, "."), 1);
$ext=str_replace("jpeg", "jpg", $ext);
If($randomname){
$rand=rand(0,100);
$name=$rand."_".time().".".$ext;
}
$error="";
If(!$file) {
$error="1";
$text .="<b>No file selected</b><br />\n";
}
If($file) {
If($maxsize) {
If($size > ($maxsize*900)) {
$error="1";
$text .="<b>Your file is to big</b><br />\n";
}
}
If($usetypes) {
If(!in_array($ext,$types)) {
$error="1";
$text .="<b>Invalid file type</b><br />\n";
}
}
If(file_exists($folder.$name)) {
$error="1";
$text .="<b>Please rename your file, filename already exists.<br /></b><br />\n";
}
}
If($error=="1") {
Echo("<div align=\"center\" class=\".text\">$text</div>\n");
@unlink($file);
} Else {
@move_uploaded_file($file,$folder.$name) or die("Couldn't copy file to server, please make sure ".$folder." is chmod 777.".copyright());
exit("<div align=\"center\" class=\".text\"><b>File uploaded! <br /><br /><a href=\"".$url.$name."\"><b>".$url.$name."</a><br /><br />For use on a Forum: [img]".$url.$name."[/img]</b><br /><br /><a href=\"".$_SERVER['PHP_SELF']."\"><b>Click here to Upload another file.</a></b><p><img src=".$url.$name."></div> \n");
}
}
/* Below is the upload form. Edit as you wish. Note: Editing this section without knowing what you are doing may result in a usuless script. */
?>
</p>
</div>
<div align="center"><br>
</div>
<div align="center"></div>
<form action="<?Echo($_SERVER['PHP_SELF']);?>" method="POST" enctype="multipart/form-data">
<table width="0%" border="2" align="center" cellpadding="5" cellspacing="0" bordercolor="51462f" bgcolor="b8a987">
<tr>
<td bordercolor="0"><div align="center">
<table width="400" border="0" align="center" cellpadding="5" cellspacing="0" bordercolor="#666666" bgcolor="#cec7b8" class="text" style="border-collapse: collapse">
<tr>
<td colspan="2" align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif">Allowed
Types:</font></b> <?Echo(implode(", ",$types))?></td>
</tr>
<tr>
<td colspan="2" align="center"><b><font face="Verdana, Arial, Helvetica, sans-serif">Max
File Size:</font></b>
<?If(!$maxsize){Echo("No Limit");}Else{Echo($maxsize."kb");}?>
</td>
</tr>
<tr>
<td width="149" align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif">Select
file to upload:</font></b> </td>
<td width="219" align="center"><input type="file" name="file"></td>
</tr>
<tr>
<input type="hidden" name="doupload" value="True">
<td colspan="2" align="center"><input type="submit" name="doupload" value=" Upload File ">
<input type="reset" name="reset" value=" Reset Form "></td>
</tr>
</table>
</div></td>
</tr>
</table>
</form>
<div align="center">
<p> </p>
</div>
There's some other stuff in there, but you get the point. The script doesn't do anything fancy with the images, just uploads them to the same dir that the script is in.
After searching for watermark scripts, I have found several, like these:
http://phpbuilder.com/board/showthread.php?t=10298566&highlight=watermark
http://www.sitepoint.com/article/watermark-images-php
Is there an easy way to combine the two? Any help appriciated, thanks. :o