SuperSizer($strPath, $strSavePath, $strType, $value, $Quality, $filter, $fa1, $fa2, $fa3, $fa4); } function SuperSizer($strPath, $strSavePath, $strType = 'W', $value = '150', $Quality = 85, $boolProtect = true, $filter, $fa1, $fa2, $fa3, $fa4){ //save the image/path details $this->strOriginalImagePath = str_replace(" ", "%20", $strPath); $this->strResizedImagePath = $strSavePath; $this->boolProtect = $boolProtect; //get the image dimensions $this->arrOriginalDetails = getimagesize($this->strOriginalImagePath); $this->arrResizedDetails = $this->arrOriginalDetails; //create an image resouce to work with $this->resOriginalImage = $this->createImage($this->strOriginalImagePath); //select the image resize type switch(strtoupper($strType)){ case 'P': $this->resizeToPercent($value, $Quality, $filter, $fa1, $fa2, $fa3, $fa4); break; case 'H': $this->resizeToHeight($value, $Quality, $filter, $fa1, $fa2, $fa3, $fa4); break; case 'C': $this->resizeToCustom($value, $Quality, $filter, $fa1, $fa2, $fa3, $fa4); break; case 'W': default: $this->resizeToWidth($value, $Quality, $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(){ $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; } } 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]) imagepng($this->resResizedImage, $this->strResizedImagePath, 7); 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, $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); imageantialias($this->resResizedImage, true); }else if($this->arrOriginalDetails['mime']=='image/gif'){ //GIF image $this->resResizedImage = imagecreatetruecolor($numWidth, $numHeight); 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); } //update the image size details $this->updateNewDetails(); //do the actual image resize imagecopyresampled($this->resResizedImage, $this->resOriginalImage, 0, 0, 0, 0, $numWidth, $numHeight, $this->arrOriginalDetails[0], $this->arrOriginalDetails[1]); if($filter!=""){ $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, $filter, $fa1, $fa2, $fa3, $fa4){ $numHeight=(int)(($numWidth*$this->arrOriginalDetails[1])/$this->arrOriginalDetails[0]); $this->_resize($numWidth, $numHeight, $Quality, $filter, $fa1, $fa2, $fa3, $fa4); } function resizeToHeight($numHeight, $Quality, $filter, $fa1, $fa2, $fa3, $fa4){ $numWidth=(int)(($numHeight*$this->arrOriginalDetails[0])/$this->arrOriginalDetails[1]); $this->_resize($numWidth, $numHeight, $Quality, $filter, $fa1, $fa2, $fa3, $fa4); } function resizeToPercent($numPercent, $Quality, $filter, $fa1, $fa2, $fa3, $fa4){ $numWidth = (int)(($this->arrOriginalDetails[0]/100)*$numPercent); $numHeight = (int)(($this->arrOriginalDetails[1]/100)*$numPercent); $this->_resize($numWidth, $numHeight, $Quality, $filter, $fa1, $fa2, $fa3, $fa4); } function resizeToCustom($size, $Quality, $filter, $fa1, $fa2, $fa3, $fa4){ if(!is_array($size)){ $this->_resize((int)$size, (int)$size, $Quality, $filter, $fa1, $fa2, $fa3, $fa4); }else{ $this->_resize((int)$size[0], (int)$size[1], $Quality, $filter, $fa1, $fa2, $fa3, $fa4); } } function recursive_rmdir($dir) { // all subdirectories and contents: if(is_dir($dir))$dir_handle=opendir($dir); 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(); //get and set the parameters $debugIT = isset($params['debugIT']) ? $params['debugIT']:false; $noOutPut = isset($params['noOutPut']) ? $params['noOutPut']:false; $path = isset($params['path']) ? $params['path']:false; $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); } $cacheBuster = isset($params['cacheBuster']) ? $params['cacheBuster']:false; $filter = isset($params['filter']) ? $params['filter'] : ""; $fa1 = isset($params['farg1']) ? $params['farg1'] : ""; $fa2 = isset($params['farg2']) ? $params['farg2'] : ""; $fa3 = isset($params['farg3']) ? $params['farg3'] : ""; $fa4 = isset($params['farg4']) ? $params['farg4'] : ""; $URL = isset($params['URL']) ? $params['URL']:''; $Assign = isset($params['Assign']) ? $params['Assign']:''; $OlDextension = substr($path, (strrpos($path,".")+1)); $extension = strtolower(substr($path, (strrpos($path,".")+1))); $filebasename = basename($path, $OlDextension); 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))=="/"){substr_replace($Subdir, '', 0, 1);} if ((substr($Subdir, -1))!="/"){$Subdir.="/";} } if ((substr($path, 0,1))=="/"){$Cpath=substr_replace($path, '', 0, 1);} $rootUrl = isset($params['rootUrl']) ? $params['rootUrl'] : $config['uploads_url']; $filenameCampair=$config['uploads_path']."/".$Cpath; $filename=$config['uploads_path']."/SuperSizerTmp/".$Subdir.$Prefix.$filebasename."-w".$width."-h".$height."-p".$percentage."-F".$filter.$Suffix.".".$extension; $fileLINK=$rootUrl."/SuperSizerTmp/".$Subdir.$Prefix.$filebasename."-w".$width."-h".$height."-p".$percentage."-F".$filter.$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($filenameCampair)){ unlink ($filename); } } if($_POST['clearcache']==1){ unlink ($config['uploads_path']."/SuperSizerTmp/"); } 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; if($width>0 || $height>0) { if ($width>0 && $height==0){ $objResize = new SuperSizer($path, $filename, 'W', $width, $Quality, $Protect,$filter, $fa1, $fa2, $fa3, $fa4); }elseif($height>0 && $width==0){ $objResize = new SuperSizer($path, $filename, 'H', $height, $Quality, $Protect, $filter, $fa1, $fa2, $fa3, $fa4); }else{ $objResize = new SuperSizer($path, $filename, 'C', array($width, $height), $Quality, $Protect, $filter, $fa1, $fa2, $fa3, $fa4); } }else{ $objResize = new SuperSizer($path, $filename, 'P', $percentage, $Quality, $Protect,$filter, $filterarg1, $fa1, $fa2, $fa3, $fa4); } 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'].'" ':''; if($Assign!=''){ $smarty->assign($Assign,"
Just insert the tag into your template/page like in one of the examples here:
1. {supersizer path='uploads/images/test.jpg' percentage='25'}
2. {supersizer path='uploads/images/test.jpg' width='320'} (With aspect ratio)
3. {supersizer path='uploads/images/test.jpg' height='240'} (With aspect ratio)
4. {supersizer path='uploads/images/test.jpg' width='150' height='140'} (Aspect ratio depends on given width, height)
5. {supersizer path="$LogoSub" width='150' rootUrl="http://media.domain.org/uploads"}
5. {supersizer path="$LogoSub" width='150' Quality=55 Protect=false}
5. {supersizer path="$LogoSub" width='150' class='LogoImg' alt="$Name" rootUrl="http://media.domain.org/uploads" Quality=55}
path - Image full pathname eg: uploads/images/test.jpg or $entry->logo_path in Company Directory etc...rootUrl (optional) - supersizer creates a temp director in the upload folder. If you move the path to the uplaod to a subdomain you may guide the output with this.$config['uploads_path'] = '/var/www/vhosts/domain.org/httpdocs/uploads'; $config['uploads_path'] = '/var/www/vhosts/domain.org/subdomains/media/httpdocs/uploads';cacheBuster (optional) Default:false - This is to instantly uncache an image on the client side after a new uploaded photo is SuperSized... ie: Canyon House.-w150-h0-p0.jpg?1255225007 ( true/false )Protect (optional) Default:false - Don't resize if smaller.. ie: don't size up if true ( true/false )Quality (optional) Default:85 - Resize image at set Quality(NOTE: 1-100 ).class (optional) - Add a classalt (optional) - Add an altid (optional) - Add an idtitle (optional) - Add a titlestripTag (optional) Default:false - stripTag take a full img tag passed in by the param path="" and makes it usable for SuperSizer ( true/false )URL (optional) - just sizes and outputs the url. you could use this in and XML output, lets say to make a map icon for CGGoogleMaps thru a CGFeedmaker output of a kml/xmlnoOutPut (optional) Default:false - just sizes the image. This is good for galleries ( true/false )Prefix (optional) - Add a Prefix to the temp file nameSuffix (optional) - Add a Suffix to the temp file nameSubdir (optional) - Create Subfolders -- Organize your photos from within the SuperSizerTmp folder ( Subdir=$oneuser.id or Subdir="foo/bar")filter (optional) - EX: filter="NEGATE"
farg1 (optional) - First argument for the filtersfarg2 (optional) - Second argument for the filtersfarg3 (optional) - Third argument for the filtersfarg4 (optional) - Fourth argument for the filterspercentage (optional) - Resize image in percent of original eg. 50%.width (optional) - Resize image on width and height will resize accordingly to keep aspect ratioheight (optional) - Resize image on height and width will resize accordingly to keep aspect ratio Assign (optional) - Assign the output (return the smarty assignment) Use in conjunction with out without URLdebugIT (optional) Default:false - Get an array of the pre and post images... the original and the resized height and width (optional)
Important:You may use width in conjunction with height in order to resize image to an absolute size of your control. Aspect ratio is then, dependent on the values you use. If no parameters for resizing are passed (except for the path) then a resizing with a percentage value of 25% is performed by default
Author: jeremyBass <jeremybass@cableone.net>
Website: CorbensProducts.com
Support more mods like this:
Author: jeremyBass <jeremybass@cableone.net>
Version: 1.8, 11.27.2009