<?php
/////////////////////////////////////////////////////////////////////////////////////////////
// @Author : Subash P S
// @Titlte : Example for thumanail and watermark generation
// @Created Date : 13 Oct 2010
// @Modified Date : 13 Oct 2010
// @Descrtion : This is a example script for generating thumbnail for the uploaded image
// This is also generate watermark text on both uploaded image and thubnails.
// @Email : <hide@address.com>
// @version : 1.0 alpha
/////////////////////////////////////////////////////////////////////////////////////////////
require_once 'config.php';
$util = new Util();
$thumb = new Thumb();
$log = new Errorlog();
$errorMessage = '';
if(isset($_POST['upload']))
{
if ($_FILES["fileup"]["error"] > 0)
{
$errorMessage = $_FILES["fileup"]["error"];
}
else
{
if($util->isImage($_FILES["fileup"]['type']))
{
if($_FILES["fileup"]['type']<MAX_SIZE)
{
$imgext = $util->getImageExt($_FILES["fileup"]["name"]);
$newImgNamePart1 = time();
$newImgName = $newImgNamePart1.".".$imgext;
// Upload the image to destination Folder
if(move_uploaded_file($_FILES["fileup"]["tmp_name"], IMG_UP_DIR ."/". $newImgName))
{
chmod(IMG_UP_DIR ."/". $newImgName,0777);//Set Permissionsa
if(!$thumb->createThumb($newImgName))//Create Thumbnail,Image name is only the param
{
print "<br>Failed on creating thumbnail image";
$log->writeLog('Failed on creating thumbnail image');
}
if(!$thumb->addWatermark(IMG_UP_DIR ."/". THUMB_DIR."/thumb_".$newImgName,"Copyrighted Image "))//Create watermark on thumbnail
{
print "<br>Failed on creating watermark on thumbnail image";
$log->writeLog('Failed on creating watermark on thumbnail image');
}
if(!$thumb->addWatermark(IMG_UP_DIR ."/". $newImgName,"Copyrighted Image "))// Create watermark on the uploadedimage
{
print "<br>Failed on creating watermark on uploaded image";
$log->writeLog('Failed on creating watermark on uploaded image');
}
$errorMessage = "Uploaded";
}
else
{
$errorMessage = "Upload Error";
}
}
else
{
$errorMessage = "Image Size exeed";
}
}
else
{
$errorMessage = "Invalid Image";
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
<head>
<title> :: Example PHP Thumbnail Generator ::</title>
</head>
<body>
<br/><br/><br/><br/><br/><br/>
<center>
<div style="color:red"><?php print $errorMessage;?></div>
<form action="<?php echo $_SERVER['PHP_SELF'];?> " method="post" enctype="multipart/form-data">
<label>Upload File</label>
<input type='file' id='fileup' name='fileup'/>
<input type="submit" name="upload" value="upload"/>
</form>
</center>
</body>
</html>