<?php
require($_SERVER["DOCUMENT_ROOT"]."/ui/engine.php");
define("PAGETITLE", "Avatar Resize-o-Matic");
//Written by JWC for the APF Forums
//August-September 2006
//Makes use of a modified version of Harish Chauhan's Image Resizer. Modifications occur at lines 228, 229, 239, 240, 250, and 251. They are for the purpose of making the browser save the file as an actual file.
// VARIABLES
//NAME //DESCRIPTION
$ud = "avres/"; //The directory for storing files.
$maxFileSize = 10000000; //The maximum size in bytes that an uploaded file can be.
$ftypes = array("gif","jpg","png","jpeg");
//^ Allowed filetypes.
if (!$_REQUEST['action']) {
printheader();
ds("Introduction", "
Welcome to the Avatar Resize-o-matic. This short script will automatically resize avatars that are over a maximum dimension, preserving the aspect ratio. Please select a file to upload by pressing the Browse button. Then, press Go to resize your file (if it needs resizing). After it has finished, you should be presented with a Save dialog box. Save the image and then upload your newly resized image to <a href=\"http://imageshack.us/\">ImageShack</a> or some other hosting service.");
ds("Resize your Image!", "</p>
<form method=\"post\" name=\"avres\" action=\"avresomatic.php\" enctype=\"multipart/form-data\">
<input type=\"hidden\" name=\"action\" value=\"createImage\" />
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"<?php echo($maxFileSize); ?>\" />
<p> Upload file: <input type=\"file\" name=\"upFile\" /></p>
<p> Maximum Dimension: <input type=\"text\" name=\"maxDim\" value=\"100\"/> pixels</p>
<p> <input type=\"submit\" name=\"go\" value=\"Go >\" /></p>
</form><p>");
printfooter();
}
elseif ($_REQUEST['action']=="createImage") {
$ufname = stripslashes(basename($_FILES['upFile']['name']));
$fnf = explode(".", $ufname);
$fext = strtolower($fnf[count($fnf)-1]);
if (in_array($fext, $ftypes)) {
$uf = $ud.$ufname;
if (move_uploaded_file(stripslashes($_FILES['upFile']['tmp_name']), $uf)!=1) die("File upload failed.");
chmod($uf, 0755);
//Get width and height. Then, define new width and height:
$maxDim = $_REQUEST['maxDim'];
$imgprop = getimagesize($uf);
$width = $imgprop[0];
$height = $imgprop[1];
if ($width<=$maxDim && height<=$maxDim) {
die("Your image is fine. It needs no resizing!");
}
elseif ($width>=$maxDim && $width>$height) {
$oldWidth = $width;
$width = $maxDim;
$height = $maxDim * $height / $oldWidth;
}
else {
$oldHeight = $height;
$height = $maxDim;
$width = $maxDim * $width / $oldHeight;
}
//Perform manipulations here.
include_once($ud."resizeimage.inc.php");
$rimg=new RESIZEIMAGE($uf);
echo $rimg->error();
$rimg->resize_limitwh($width, $height);
$rimg->close();
//Delete original file.
unlink($uf);
}
else die("Filetype not permitted.");
}
else die("Be sensible.");
?>