SuperSizer($strPath, $strSavePath, $strType, $value, $Quality, $crop, $SAMPLE, $boolProtect, $filter, $fa1, $fa2, $fa3, $fa4);
}
function SuperSizer($strPath='', $strSavePath='', $strType = 'W', $value = '150', $Quality = 85, $crop=false, $SAMPLE=true, $boolProtect = true, $filter=null, $fa1=null, $fa2=null, $fa3=null, $fa4=null){
if($strSavePath!=''){
//$this->strOriginalImagePath = str_replace(" ", "%20", $strPath);
$this->strOriginalImagePath = rawurldecode($strPath);
$this->strResizedImagePath = $strSavePath;
$this->boolProtect = $boolProtect;
//get the image dimensions
if(!@getimagesize($this->strOriginalImagePath)){
$this->errors[]= "There is a path issue!
Does this look right?
Path:".$this->strOriginalImagePath."
";
return false;
}else{
$this->arrOriginalDetails = getimagesize($this->strOriginalImagePath);
}
$this->arrResizedDetails = $this->arrOriginalDetails;
//create an image resouce to work with
$this->resOriginalImage = $this->createImage($this->strOriginalImagePath);
if(!@imagesx($this->resOriginalImage)){
$this->errors[]= 'You have an image that has Corrupted header!';
return false;
}
//select the image resize type
switch(strtoupper($strType)){
case 'P':
$this->resizeToPercent($value, $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4);
break;
case 'H':
$this->resizeToHeight($value, $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4);
break;
case 'C':
$this->resizeToCustom($value, $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4);
break;
case 'W':
default:
$this->resizeToWidth($value, $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4);
break;
}
}
}
function findResourceDetails($resImage){
//check to see what image is being requested
if($resImage==$this->resResizedImage){
//return new image details
return $this->arrResizedDetails;
}else{
//return original image details
return $this->arrOriginalDetails;
}
}
function updateNewDetails(){
if(!@imagesx($this->resResizedImage)){
$this->errors[]= 'You have an image that has Corrupted header!';
return false;
}
$this->arrResizedDetails[0] = imagesx($this->resResizedImage);
$this->arrResizedDetails[1] = imagesy($this->resResizedImage);
}
function createImage($strImagePath){
//get the image details
$arrDetails = $this->findResourceDetails($strImagePath);
//choose the correct function for the image type
switch($arrDetails['mime']){
case 'image/jpeg':
return imagecreatefromjpeg($strImagePath);
break;
case 'image/png':
return imagecreatefrompng($strImagePath);
break;
case 'image/gif':
return imagecreatefromgif($strImagePath);
break;
}
}
function filters($filter, $fa1, $fa2, $fa3, $fa4){
//choose the correct function for the image type
switch($filter){
case 'NEGATE':
return imagefilter($this->resResizedImage, IMG_FILTER_NEGATE);
break;
case 'GRAYSCALE':
return imagefilter($this->resResizedImage, IMG_FILTER_GRAYSCALE);
break;
case 'BRIGHTNESS':
return imagefilter($this->resResizedImage, IMG_FILTER_BRIGHTNESS, $fa1);
break;
case 'CONTRAST':
return imagefilter($this->resResizedImage, IMG_FILTER_CONTRAST, $fa1);
break;
case 'COLORIZE':
return imagefilter($this->resResizedImage, IMG_FILTER_COLORIZE, $fa1, $fa2, $fa3, $fa4);
break;
case 'EDGEDETECT':
return imagefilter($this->resResizedImage, IMG_FILTER_EDGEDETECT);
break;
case 'EMBOSS':
return imagefilter($this->resResizedImage, IMG_FILTER_EMBOSS);
break;
case 'GAUSSIAN_BLUR':
return imagefilter($this->resResizedImage, IMG_FILTER_GAUSSIAN_BLUR);
break;
case 'SELECTIVE_BLUR':
return imagefilter($this->resResizedImage, IMG_FILTER_SELECTIVE_BLUR);
break;
case 'MEAN_REMOVAL':
return imagefilter($this->resResizedImage, IMG_FILTER_MEAN_REMOVAL);
break;
case 'SMOOTH':
return imagefilter($this->resResizedImage, IMG_FILTER_SMOOTH, $fa1);
break;
case 'PIXELATE':
return imagefilter($this->resResizedImage, IMG_FILTER_PIXELATE, $fa1,$fa2);
break;
case 'IMAGEHUE':
$this->imagefilterhue($this->resResizedImage,$fa1, $fa2, $fa3);
break;
}
}
function imagefilterhue($im,$r,$g,$b){
$rgb = $r+$g+$b;
$col = array($r/$rgb,$b/$rgb,$g/$rgb);
$height = imagesy($im);
$width = imagesx($im);
for($x=0; $x<$width; $x++){
for($y=0; $y<$height; $y++){
$rgb = ImageColorAt($im, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$newR = $r*$col[0] + $g*$col[1] + $b*$col[2];
$newG = $r*$col[2] + $g*$col[0] + $b*$col[1];
$newB = $r*$col[1] + $g*$col[2] + $b*$col[0];
$img=imagesetpixel($im, $x, $y,imagecolorallocate($im, $newR, $newG, $newB));
}
}
return $img;
}
function saveImage($Quality = 85){
switch($this->arrResizedDetails['mime']){
case 'image/jpeg':
imagejpeg($this->resResizedImage, $this->strResizedImagePath, $Quality);
break;
case 'image/png':
// imagepng = [0-9] (not [0-100])
$newNumber=$Quality/10;
$Quality = number_format($newNumber, 0, '.', '');
imagepng($this->resResizedImage, $this->strResizedImagePath, $Quality);
break;
case 'image/gif':
imagegif($this->resResizedImage, $this->strResizedImagePath);
break;
}
}
function showImage($resImage){
//get the image details
$arrDetails = $this->findResourceDetails($resImage);
//set the correct header for the image we are displaying
header("Content-type: ".$arrDetails['mime']);
switch($arrDetails['mime']){
case 'image/jpeg':
return imagejpeg($resImage);
break;
case 'image/png':
return imagepng($resImage);
break;
case 'image/gif':
return imagegif($resImage);
break;
}
}
function destroyImage($resImage){
imagedestroy($resImage);
}
function _resize($numWidth, $numHeight, $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4){
//check for image protection
if($this->_imageProtect($numWidth, $numHeight)){
if($this->arrOriginalDetails['mime']=='image/jpeg'){
//JPG image
$this->resResizedImage = imagecreatetruecolor($numWidth, $numHeight);
imageinterlace($this->resResizedImage, false);
//imageantialias($this->resResizedImage, true);
}else if($this->arrOriginalDetails['mime']=='image/gif'){
//GIF image
$this->resResizedImage = imagecreatetruecolor($numWidth, $numHeight);
imagetruecolortopalette($this->resResizedImage, true, 256);
//imageantialias($this->resResizedImage, true);
imagealphablending($this->resResizedImage, false);
imagesavealpha($this->resResizedImage,true);
$transparent = imagecolorallocatealpha($this->resResizedImage, 255, 255, 255, 127);
imagefilledrectangle($this->resResizedImage, 0, 0, $numWidth, $numHeight, $transparent);
imagecolortransparent($this->resResizedImage, $transparent);
}else if($this->arrOriginalDetails['mime']=='image/png'){
//PNG image
$this->resResizedImage = imagecreatetruecolor($numWidth, $numHeight);
imagecolortransparent($this->resResizedImage, imagecolorallocate($this->resResizedImage, 0, 0, 0));
// Turn off transparency blending (temporarily)
imagealphablending($this->resResizedImage, false);
// Create a new transparent color for image
$color = imagecolorallocatealpha($this->resResizedImage, 0, 0, 0, 127);
// Completely fill the background of the new image with allocated color.
imagefill($this->resResizedImage, 0, 0, $color);
// Restore transparency blending
imagesavealpha($this->resResizedImage, true);
}
$src_x = 0;
$src_y = 0;
$dst_x = 0;
$dst_y = 0;
$dst_w=$numWidth;
$dst_h=$numHeight;
$src_w=$this->arrOriginalDetails[0];
$src_h=$this->arrOriginalDetails[1];
$crop="true";
if($crop[0]==true){
if(strlen($crop)>=4){$crop=explode(",", $crop);}else{$crop="true,0,0";}
//if the image is smaller than crop size
//we're always going to crop from center
$src_x = $src_y = 0;
$src_w = $src_w;
$src_h = $src_h;
$cmp_x = $src_w / $dst_w;
$cmp_y = $src_h / $dst_h;
// calculate x or y coordinate and width or height of source
if ( $cmp_x > $cmp_y ) {
$src_w = round( ( $src_w / $cmp_x * $cmp_y ) );
$src_x = round( ( $src_w - ( $src_w / $cmp_x * $cmp_y ) ) / 2 )+$crop[1];
} elseif ( $cmp_y > $cmp_x ) {
$src_h = round( ( $src_h / $cmp_y * $cmp_x ) );
$src_y = round( ( $src_h - ( $src_h / $cmp_y * $cmp_x ) ) / 2 )+$crop[2];
}
}
//update the image size details
$this->updateNewDetails();
if($SAMPLE==true){
//do the actual image resize
imagecopyresampled($this->resResizedImage, $this->resOriginalImage, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
}else{
imagecopyresized ($this->resResizedImage, $this->resOriginalImage, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
}
if($filter!=""){
//filter
// Here we split the variables.
$FiltersArray = explode(",", $filter);
$Fa1Array = explode(",", $fa1);
$Fa2Array = explode(",", $fa2);
$Fa3Array = explode(",", $fa3);
$Fa3Array = explode(",", $fa4);
$i = 0;
foreach ($FiltersArray as $Filter){
$this->filters($FiltersArray[$i], $Fa1Array[$i], $Fa2Array[$i], $Fa3Array[$i], $Fa4Array[$i]);
$i++;
}
//$this->filters($filter, $fa1, $fa2, $fa3, $fa4);
}
//saves the image
$this->saveImage($Quality);
}
}
function _imageProtect($numWidth, $numHeight){
if($this->boolProtect AND ($numWidth > $this->arrOriginalDetails[0] OR $numHeight > $this->arrOriginalDetails[1])){
return 0;
}
return 1;
}
function resizeToWidth($numWidth, $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4){
$numHeight=(int)(($numWidth*$this->arrOriginalDetails[1])/$this->arrOriginalDetails[0]);
$this->_resize($numWidth, $numHeight, $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4);
}
function resizeToHeight($numHeight, $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4){
$numWidth=(int)(($numHeight*$this->arrOriginalDetails[0])/$this->arrOriginalDetails[1]);
$this->_resize($numWidth, $numHeight, $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4);
}
function resizeToPercent($numPercent, $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4){
$numWidth = (int)(($this->arrOriginalDetails[0]/100)*$numPercent);
$numHeight = (int)(($this->arrOriginalDetails[1]/100)*$numPercent);
$this->_resize($numWidth, $numHeight, $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4);
}
function resizeToCustom($size, $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4){
if(!is_array($size)){
$this->_resize((int)$size, (int)$size, $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4);
}else{
$this->_resize((int)$size[0], (int)$size[1], $Quality, $crop, $SAMPLE, $filter, $fa1, $fa2, $fa3, $fa4);
}
}
function recursive_rmdir($dir)
{
// all subdirectories and contents:
if(is_dir($dir)){
$dir_handle=opendir($dir);
}else{
return false;
}
while($file=readdir($dir_handle))
{
if($file!="." && $file!="..")
{
if(!is_dir($dir."/".$file))unlink ($dir."/".$file);
else $this->recursive_rmdir($dir."/".$file);
}
}
closedir($dir_handle);
rmdir($dir);
return true;
}
}
function smarty_cms_function_supersizer($params, &$smarty) {
global $gCms;
$config =& $gCms->GetConfig();
$debugIT = isset($params['debugIT']) ? $params['debugIT']:false;
$noOutPut = isset($params['noOutPut']) ? $params['noOutPut']:false;
$Assign = isset($params['Assign']) ? $params['Assign']:'';
$path = isset($params['path']) ? $params['path']:false;
$orginPath=$path;
$Prefix = isset($params['Prefix']) ? $params['Prefix']:'';
$Suffix = isset($params['Suffix']) ? $params['Suffix']:'';
$Subdir = isset($params['Subdir']) ? $params['Subdir'] : "";
$stripTags = isset($params['stripTags']) ? $params['stripTags'] : false;
if($stripTags==true){
$path = preg_replace('/.*src=([\'"])((?:(?!\1).)*)\1.*/si','$2',$path);
}
$removeUniqueness = isset($params['removeUniqueness']) ? $params['removeUniqueness'] : false;
$URL = isset($params['URL']) ? $params['URL']:'';
$OlDextension = substr($path, (strrpos($path,".")+1));
$extension = strtolower(substr($path, (strrpos($path,".")+1)));
$filebasename = basename($path, $OlDextension);
$crop = isset($params['crop']) ? $params['crop'] : false;
$SAMPLE = isset($params['Sample']) ? $params['Sample']:true;
$filter = isset($params['filter']) ? $params['filter'] : "";
if(!isset($params['width']) && !isset($params['height']) && !isset($params['percentage'])) {
$percentage = 25;
}else{
$width = isset($params['width']) ? intval($params['width']) : 0;
$height = isset($params['height']) ? intval($params['height']) : 0;
$percentage = isset($params['percentage']) ? intval($params['percentage']) : 0;
}
if(isset($Subdir)){
if ((substr($Subdir, 0,1))=="/"){$Subdir=substr_replace($Subdir, '', 0, 1);}
if (((substr($Subdir, -1))!="/")&&$Subdir!=''){$Subdir.='/';}
}
if(isset($path)){
if ((substr($path, 0,5))=="http:"){$L=strlen($config['root_url']);$path = substr_replace($path, '', 0, $L);}
if ((substr($path, 0,1))=='/'){$path=substr_replace($path, '', 0, 1);}
}else{
echo "You have forgoten to define the orginal image. Please do so.";
}
$U='';
if($removeUniqueness==false){
$U="-w".$width."-h".$height."-p".$percentage."-F".$filter."-S".$SAMPLE;
}
$path=$config['root_path']."/".$path;
$rootUrl = isset($params['rootUrl']) ? $params['rootUrl'] : $config['uploads_url'];
$filename=$config['uploads_path']."/SuperSizerTmp/".$Subdir.$Prefix.$filebasename.$U.$Suffix.".".$extension;
$fileLINK=$rootUrl."/SuperSizerTmp/".$Subdir.$Prefix.$filebasename.$U.$Suffix.".".$extension;
$Protect= isset($params['Protect']) ? $params['Protect'] : true;
if(file_exists($filename)){
if($debugIT==true){
unlink ($filename);
//smarty_cms_function_supersizer($params, &$smarty);
}elseif(@filemtime($filename) < @filemtime($path)){
unlink ($filename);
}
}
if(!file_exists($filename)){
if(!file_exists($config['uploads_path']."/SuperSizerTmp/".$Subdir)){
mkdir($config['uploads_path']."/SuperSizerTmp/".$Subdir, 0777, true);
}
$Quality = isset($params['Quality']) ? intval($params['Quality']) : 85;
$passThru = isset($params['passThru']) ? $params['passThru']:false;
$showErrors = isset($params['showErrors']) ? $params['showErrors']:true;
$cacheBuster = isset($params['cacheBuster']) ? $params['cacheBuster']:false;
$fa1 = isset($params['farg1']) ? $params['farg1'] : "";
$fa2 = isset($params['farg2']) ? $params['farg2'] : "";
$fa3 = isset($params['farg3']) ? $params['farg3'] : "";
$fa4 = isset($params['farg4']) ? $params['farg4'] : "";
if($width>0 || $height>0) {
if ($width>0 && $height==0){
$objResize = new SuperSizer($path, $filename, 'W', $width, $Quality, $crop, $SAMPLE, $Protect,$filter, $fa1, $fa2, $fa3, $fa4);
}elseif($height>0 && $width==0){
$objResize = new SuperSizer($path, $filename, 'H', $height, $Quality, $crop,$SAMPLE, $Protect, $filter, $fa1, $fa2, $fa3, $fa4);
}else{
$objResize = new SuperSizer($path, $filename, 'C', array($width, $height), $Quality, $crop, $SAMPLE, $Protect, $filter, $fa1, $fa2, $fa3, $fa4);
}
}else{
$objResize = new SuperSizer($path, $filename, 'P', $percentage, $Quality, $crop, $SAMPLE, $Protect,$filter, $filterarg1, $fa1, $fa2, $fa3, $fa4);
}
if($debugIT==true){
print_r($objResize);
}
if($showErrors==true){
foreach($objResize->errors as $error){
echo $error;
}
}
if($passThru==true){
if($objResize->resResizedImage==''){
if($URL!=true){
$class = isset($params['class']) ? ' class="'.$params['class'].'" ':'';
$alt = isset($params['alt']) ? ' alt="'.$params['alt'].'" ':'';
$id = isset($params['id']) ? ' id="'.$params['id'].'" ':'';
$title = isset($params['title']) ? ' title="'.$params['title'].'" ':'';
$style = isset($params['style']) ? ' style="'.$params['style'].'" ':'';
$tagWidth = isset($params['tagWidth']) ? ' width="'.$params['tagWidth'].'" ':'';
$tagHeight = isset($params['tagHeight']) ? ' height="'.$params['tagHeight'].'" ':'';
if($Assign!=''){
$smarty->assign($Assign, "");
}else{
echo "
";
}
}else{
if($Assign!=''){
$smarty->assign($Assign,$orginPath);
}else{
echo $orginPath;
}
}
return false;
}
}
if($debugIT==true){
echo '
'; print_r($objResize->findResourceDetails($objResize->resOriginalImage)); echo '
'; print_r($objResize->findResourceDetails($objResize->resResizedImage)); echo ''; error_reporting(E_ALL); } } if($noOutPut==false){ if($cacheBuster==true){ $fileLINK=$fileLINK."?".@filemtime($filename); } if($URL!=true){ $class = isset($params['class']) ? ' class="'.$params['class'].'" ':''; $alt = isset($params['alt']) ? ' alt="'.$params['alt'].'" ':''; $id = isset($params['id']) ? ' id="'.$params['id'].'" ':''; $title = isset($params['title']) ? ' title="'.$params['title'].'" ':''; $style = isset($params['style']) ? ' style="'.$params['style'].'" ':''; $tagWidth = isset($params['tagWidth']) ? ' width="'.$params['tagWidth'].'" ':''; $tagHeight = isset($params['tagHeight']) ? ' height="'.$params['tagHeight'].'" ':''; if($Assign!=''){ $smarty->assign($Assign,"
Author: jeremyBass <jeremybass@cableone.net>
Website: CorbensProducts.com
Support more mods like this:
Author: jeremyBass <jeremybass@cableone.net>
Version: BETA 0.9.1, 2.16.2010