|
Server : Apache/2.4.62 System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64 User : www ( 80) PHP Version : 8.3.8 Disable Function : NONE Directory : /domains/owens.enteract/inc/libs/photocropper/ |
Upload File : |
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set("display_errors", 1);
ini_set('memory_limit','128M');
set_time_limit(0); //No script timeout
include_once('../../utils.php');
include_once('../../libs/files/FileHandler.php');
$errorMsg = "";
//Incoming data
$imgURL = ValidationUtils::getRequestVar("both","img","");
$cropXYArray = explode(",",ValidationUtils::getRequestVar("both","cropXY",""));
$cropDimArray = explode("x",ValidationUtils::getRequestVar("both","cropDim",""));
$origImgDimArray = explode("x",ValidationUtils::getRequestVar("both","origImgDim",""));
$displayImgDimArray = explode("x",ValidationUtils::getRequestVar("both","displayImgDim",""));
$actualCropDimArray = explode("x",ValidationUtils::getRequestVar("both","actualCropDim",""));
$actualCropXYArray = explode(",",ValidationUtils::getRequestVar("both","actualCropXY",""));
$desiredImgDimArray = explode("x",ValidationUtils::getRequestVar("both","desiredImgDim",""));
//Prep image handler
$imgHandler = new FileHandler();
$imgHandler->uploadTempFolder = "../../../" . CACHE_PATH;
$imgHandler->uploadFolder = "../../../" . CACHE_PATH;
//Get the actual file name so we can rename the other assets
$imgPathInfo = pathinfo(strtolower($imgURL));
$imgExtension = $imgPathInfo['extension'];
$imgFilename = uniqid() . "." . $imgExtension; //Unique up this name son
//If it's a "local" image for upload make sure path gets corrected
if (strpos($imgURL,"://") === false){
$imgURL = DYNAMIC_ASSETS_URL . $imgPathInfo['filename'] . "." . $imgPathInfo['extension'];
}
//Validate extension is valid
if ($imgExtension == "jpg" || $imgExtension == "jpeg" || $imgExtension == "png" || $imgExtension == "gif"){
//Crop image name
$tmp_crop = $imgHandler->uploadFolder . "tmp_crop_" . $imgFilename;
$tmp_final_crop = $imgHandler->uploadFolder . "tmp_final_" . $imgFilename;
//Crop larger image first
$imgHandler->cropScaledImage($imgURL,$tmp_crop,$actualCropDimArray[0],$actualCropDimArray[1],$origImgDimArray[0],$origImgDimArray[1],$actualCropXYArray[0],$actualCropXYArray[1]);
//Crop down to fit the actual image
$imgHandler->proportionalImageFit($tmp_crop,$tmp_final_crop,$desiredImgDimArray[0],$desiredImgDimArray[1]);
$imgFinalURL = DYNAMIC_ASSETS_URL . "_tmp/tmp_final_" . $imgFilename;
}else{
$errorMsg = "File is not a valid image.";
}
//RETURN ID
echo "<div id='data'>";
echo " <div id='errorMsg'>".$errorMsg."</div>";
echo " <div id='imgURL'>".$imgFinalURL."</div>";
echo "</div>";
?>