zerobytes |
Valuable expert |
![Valuable expert Valuable expert](modules/Forums/images/ranks/rang5.gif)
![](modules/Forums/images/avatars/gallery/blank.gif) |
|
Joined: Aug 30, 2008 |
Posts: 199 |
|
|
|
![](themes/Helius/forums/images/spacer.gif) |
![](themes/Helius/forums/images/spacer.gif) |
![](themes/Helius/forums/images/post_corner.gif) |
|
Code: |
ini_set("memory_limit","64M");
if (!defined('XCART_START')) {header("Location: ../../../");die("Access denied");}
function smarty_function_thumb($params,&$smarty)
{
if (!function_exists('UnsharpMask'))
{
function UnsharpMask($img,$amount,$radius,$threshold)
{
if ($amount >500) $amount = 500;
$amount = $amount * 0.016;
if ($radius >50) $radius = 50;
$radius = $radius * 2;
if ($threshold >255) $threshold = 255;
$radius = abs(round($radius));
if ($radius == 0) {return $img;imagedestroy($img);break;}
$w = imagesx($img);$h = imagesy($img);
$imgCanvas = $img;
$imgCanvas2 = $img;
$imgBlur = imagecreatetruecolor($w,$h);
for ($i = 0;$i <$radius;$i++)
{
imagecopy ($imgBlur,$imgCanvas,0,0,1,1,$w -1,$h -1);
imagecopymerge ($imgBlur,$imgCanvas,1,1,0,0,$w,$h,50);
imagecopymerge ($imgBlur,$imgCanvas,0,1,1,0,$w -1,$h,33.33333);
imagecopymerge ($imgBlur,$imgCanvas,1,0,0,1,$w,$h -1,25);
imagecopymerge ($imgBlur,$imgCanvas,0,0,1,0,$w -1,$h,33.33333);
imagecopymerge ($imgBlur,$imgCanvas,1,0,0,0,$w,$h,25);
imagecopymerge ($imgBlur,$imgCanvas,0,0,0,1,$w,$h -1,20 );
imagecopymerge ($imgBlur,$imgCanvas,0,1,0,0,$w,$h,16.666667);
imagecopymerge ($imgBlur,$imgCanvas,0,0,0,0,$w,$h,50);
}
$imgCanvas = $imgBlur;
for ($x = 0;$x <$w;$x++)
{
for ($y = 0;$y <$h;$y++)
{
$rgbOrig = ImageColorAt($imgCanvas2,$x,$y);
$rOrig = (($rgbOrig >>16) &0xFF);
$gOrig = (($rgbOrig >>8) &0xFF);
$bOrig = ($rgbOrig &0xFF);
$rgbBlur = ImageColorAt($imgCanvas,$x,$y);
$rBlur = (($rgbBlur >>16) &0xFF);
$gBlur = (($rgbBlur >>8) &0xFF);
$bBlur = ($rgbBlur &0xFF);
$rNew = (abs($rOrig -$rBlur) >= $threshold) ?max(0,min(255,($amount * ($rOrig -$rBlur)) +$rOrig)) : $rOrig;
$gNew = (abs($gOrig -$gBlur) >= $threshold) ?max(0,min(255,($amount * ($gOrig -$gBlur)) +$gOrig)) : $gOrig;
$bNew = (abs($bOrig -$bBlur) >= $threshold) ?max(0,min(255,($amount * ($bOrig -$bBlur)) +$bOrig)) : $bOrig;
if (($rOrig != $rNew) ||($gOrig != $gNew) ||($bOrig != $bNew))
{
$pixCol = ImageColorAllocate($img,$rNew,$gNew,$bNew);
ImageSetPixel($img,$x,$y,$pixCol);
}
}
}
return $img;
}
}
if (!function_exists('Watermark'))
{
function Watermark($source,$width,$height,$font,$text,$factor,$_FONTSIZE=20,$type,$trans,$loc){
if ($factor!=""){
$rel=0;
while($rel <$factor){
$size = imageTTFBBox($fontsize,0,$font,$text);
$rel=(abs($size[2])*100/$width);
$fontsize++;
}
if ($fontsize!=1) $fontsize--;
}else{
$fontsize=$_FONTSIZE;
$size = imageTTFBBox($fontsize,0,$font,$text);
}
$pos[x1]=$width-abs($size[2]+8);
if ($loc=='T') $pos[y1]=abs($size[7]-8);
elseif ($loc=='M') $pos[y1]=($height-abs($size[3]+8))/2;
else $pos[y1]=$height-abs($size[3]+8);
$pos[x2]=$width-3;
$pos[y2]=$height-3;
$white_trans = imagecolorallocatealpha($source,255,255,255,$trans);
$black_trans = imagecolorallocatealpha($source,0,0,0,($trans+20));
imagealphablending($source,true);
imagefttext($source,$fontsize,0,$pos[x1]+2,$pos[y1]+2,$black_trans,$font,$text);
imagefttext($source,$fontsize,0,$pos[x1],$pos[y1],$white_trans,$font,$text);
return $source;
imagedestroy( $source );
}
}
### Set Variables
global $config;
global $xcart_web_dir;
global $xcart_dir;
global $http_location;
global $https_location;
### Set Server Vars
$server_vars = isset($_SERVER) ?$_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
### Read Config Variables From X-Cart
$params['text'] = "© ".$config['Company']['company_name'];
$params['upscale']=$config['Dynamic_Images']['di_upscale'];
$params['quality']=$config['Dynamic_Images']['di_quality'];
$params['sharpen']=$config['Dynamic_Images']['di_sharpen'];
$params['watermark']=$config['Dynamic_Images']['di_watermark'];
$params['prefix']=$config['Dynamic_Images']['di_keyword'];
$params['font']=$config['Dynamic_Images']['di_font'];
$params['trans']=$config['Dynamic_Images']['di_trans'];
$params['watermark_loc']=$config['Dynamic_Images']['di_watermark_loc'];
### Set Image Types
$_CONFIG['types'] = array('','.gif','.jpg','.png');
### Configure Cache Directory
if (empty($params['cache'])) {
$_CONFIG['cache'] = $xcart_dir."/images/cache/";
$_CONFIG['outpath'] = $xcart_dir."/images/cache/";
$_CONFIG['webpath'] = $xcart_web_dir."/images/cache/";
}else {
$_CONFIG['cache'] = $params['cache'];
}
### Configure Image URL -Location
$string = array($http_location,$https_location);
$healthy = array("%20","%5B","%5D");
$yummy = array(" ","[","]");
$params['file'] = str_replace($healthy,$yummy,$params['file']);
if (is_file($xcart_dir.(str_replace($string,"",str_replace("./","/",$params['file'])))))
{
$params['file'] = $xcart_dir.(str_replace($string,"",str_replace("./","/",$params['file'])));
}elseif (is_file(realpath($xcart_web_dir.(str_replace($string,"",str_replace("./","/",$params['file']))))))
{
$params['file'] = realpath($xcart_web_dir.(str_replace($string,"",str_replace("./","/",$params['file']))));
}elseif (is_file(realpath($server_vars['DOCUMENT_ROOT']).$xcart_web_dir.(str_replace($string,"",str_replace("./","/",$params['file'])))))
{
$params['file'] = realpath($server_vars['DOCUMENT_ROOT']).$xcart_web_dir.(str_replace($string,"",str_replace("./","/",$params['file'])));
}else {
$params['file'] = $xcart_dir."/no_image.gif";
}
### Check/Configure All Other Variables
if (empty($params['trans'])||($params['trans'] >127)||($params['trans'] <0)) $params['trans'] = 100;
if (!empty($params['prefix'])) $params['prefix'] = $params['prefix']."-";
if (empty($params['text'])) $params['text'] = "© ".$server_vars['HTTP_HOST'];
if (empty($params['quality'])) $params['quality'] = 80;
if (empty($params['email'])) $params['email'] = N;
if (empty($params['linkonly'])) $params['linkonly'] = N;
if (empty($params['special'])) $params['special'] = N;
if (empty($params['dev'])) $params['dev'] = false;
if (empty($params['crop'])) $params['crop'] = false;
if (empty($params['width']) AND empty($params['height'])
AND empty($params['longside']) AND empty($params['shortside'])) $params['width'] = 100;
### Get SOURCE (SRC) information
$temp = getimagesize($params['file']);
$_SRC['file'] = $params['file'];
$_SRC['width'] = $temp[0];
$_SRC['height'] = $temp[1];
$_SRC['type'] = $temp[2];
$_SRC['string'] = $temp[3];
$_SRC['filename'] = basename($params['file']);
$_SRC['modified'] = filemtime($params['file']);
### Hash for Filename
$_SRC['hash'] = md5($_SRC['file'].$_SRC['modified'].implode('',$params));
### Calculate destination (DST) information
if (is_numeric($params['width'])) $_DST['width'] = $params['width'];
else $_DST['width'] = round($params['height']/($_SRC['height']/$_SRC['width']));
if (is_numeric($params['height'])) $_DST['height'] = $params['height'];
else $_DST['height'] = round($params['width']/($_SRC['width']/$_SRC['height']));
### Maintain ratio if LONGSIDE or SHORTSIDE is specified
if (is_numeric($params['longside']))
{
if ($_SRC['width'] <$_SRC['height'])
{
$_DST['height'] = $params['longside'];
$_DST['width'] = round($params['longside']/($_SRC['height']/$_SRC['width']));
}
else
{
$_DST['width'] = $params['longside'];
$_DST['height'] = round($params['longside']/($_SRC['width']/$_SRC['height']));
}
}
elseif (is_numeric($params['shortside']))
{
if ($_SRC['width'] <$_SRC['height'])
{
$_DST['width'] = $params['shortside'];
$_DST['height'] = round($params['shortside']/($_SRC['width']/$_SRC['height']));
}
else
{
$_DST['height'] = $params['shortside'];
$_DST['width'] = round($params['shortside']/($_SRC['height']/$_SRC['width']));
}
}
### Crop Image?
if($params['crop'])
{
$width_ratio = $_SRC['width']/$_DST['width'];
$height_ratio = $_SRC['height']/$_DST['height'];
if ($width_ratio >$height_ratio)
{
$_DST['offset_w'] = round(($_SRC['width']-$_DST['width']*$height_ratio)/2);
$_SRC['width'] = round($_DST['width']*$height_ratio);
}
elseif ($width_ratio <$height_ratio)
{
$_DST['offset_h'] = round(($_SRC['height']-$_DST['height']*$width_ratio)/2);
$_SRC['height'] = round($_DST['height']*$width_ratio);
}
}
### Upscale or not if the original picture is smaller than the output size
if ($params['upscale'] == 'N'&&$_DST['height'] >$_SRC['height'] &&$_DST['width'] >$_SRC['width'])
{
$_DST['width'] = $_SRC['width'];
$_DST['height'] = $_SRC['height'];
}
if (!empty($params['type'])) $_DST['type'] = $params['type'];
else $_DST['type'] = $_SRC['type'];
### Create output string
$_DST['file'] = $params['prefix'].$_SRC['hash'].$_CONFIG['types'][$_DST['type']];
$_DST['string'] = 'style="width: '.$_DST['width'].'px; height: '.$_DST['height'].'px;" alt="'.$params['alt'].'" class="'.$params['class'].'"';
if ($params['id']) {
$_DST['string'] = $_DST['string'].' id="'.$params['id'].'"';
}
if ($params['name']) {
$_DST['string'] = $_DST['string'].' name="'.$params['name'].'"';
}
### Provide return strings
if ($params['email'] == "y")
{
$_RETURN['img'] = '<img src="http://'.$server_vars['HTTP_HOST'].$_CONFIG['webpath'].$_DST['file'].'" '.$params['html'].' '.$_DST['string'].' />';
}else{
if (empty($params['html'])) $_RETURN['img'] = '<img src="'.$_CONFIG['webpath'].$_DST['file'].'" '.$params['html'].' '.$_DST['string'].' title="" />';
else $_RETURN['img'] = '<img src="'.$_CONFIG['webpath'].$_DST['file'].'" '.$params['html'].' '.$_DST['string'].' />';
}
if ($params['linkonly'] == "Y"||$params['linkonly'] == "true")
{
$returner = $_CONFIG['webpath'].$_DST['file'];
}
else
{
$returner = $_RETURN['img'];
}
### Cache file intercept
if (is_file($_CONFIG['outpath'].$_DST['file']) AND !$params['dev']) return $returner;
### Otherwise continue
### SRC read in
if ($_SRC['type'] == 1) $_SRC['image'] = imagecreatefromgif($_SRC['file']);
if ($_SRC['type'] == 2) $_SRC['image'] = imagecreatefromjpeg($_SRC['file']);
if ($_SRC['type'] == 3) $_SRC['image'] = imagecreatefrompng($_SRC['file']);
### If the picture is very large,overwrites first linear down-scaled on quadruple goal size and $_SRC
if ($_DST['width']*2 <$_SRC['width'] AND $_DST['height']*2 <$_SRC['height'])
{
$_TMP['width'] = round($_DST['width']*2);
$_TMP['height'] = round($_DST['height']*2);
$_TMP['image'] = imagecreatetruecolor($_TMP['width'],$_TMP['height']);
### Preserve transparancy on TEMP image
imagealphablending($_TMP['image'],false);
imagecopyresized($_TMP['image'],$_SRC['image'],0,0,$_DST['offset_w'],$_DST['offset_h'],$_TMP['width'],$_TMP['height'],$_SRC['width'],$_SRC['height']);
$_SRC['image'] = $_TMP['image'];
$_SRC['width'] = $_TMP['width'];
$_SRC['height'] = $_TMP['height'];
$_DST['offset_w'] = 0;
$_DST['offset_h'] = 0;
unset($_TMP['image']);
}
### DST provide
$_DST['image'] = imagecreatetruecolor($_DST['width'],$_DST['height']);
### Preserve transparancy on DST image
imagealphablending($_DST['image'],false);
### if PNG turn off unsharp mask
if ($_SRC['type'] == 3) $params['sharpen'] = "false";
imagecopyresampled($_DST['image'],$_SRC['image'],0,0,$_DST['offset_w'],$_DST['offset_h'],$_DST['width'],$_DST['height'],$_SRC['width'],$_SRC['height']);
### Unsharp Mask
if ($params['sharpen'] == "Y") $_DST['image'] = UnsharpMask($_DST['image'],80,.5,3);
### Watermark
if ($_DST['width'] >100 AND $params['watermark'] == 'Y'){
$font = $xcart_dir.$params['font'];
Watermark($_DST['image'],$_DST['width'],$_DST['height'],$font,$params['text'],'90',$_FONTSIZE=8,$_SRC['type'],$params['trans'],$params['watermark_loc']);
}
if ($params['hint'] == "Y")
{
$trans = imagecolorallocatealpha($_DST['image'],255,255,255,25);
imagefilledrectangle($_DST['image'],0,$_DST['height']-9,$_DST['width'],$_DST['height'],$trans);
$magnifier = imagecreatefromstring(gzuncompress(base64_decode("eJzrDPBz5+WS4mJgYOD19HAJAtLcIMzBBiRXrilXA1IsxU6eIRxAUMOR0gHkcxZ4RBYD1QiBMOOlu3V/gIISJa4RJc5FqYklmfl5CiGZuakMBoZ6hkZ6RgYGJs77ex2BalRBaoLz00rKE4tSGXwTk4vyc1NTMhMV3DKLUsvzi7KLFXwjFEAa2svWnGdgYPTydHEMqZhTOsE++1CAyNHzm2NZjgau+dAmXlAwoatQmOld3t/NPxlLMvY7sovPzXHf7re05BPzjpQTMkZTPjm1HlHkv6clYWK43Zt16rcDjdZ/3j2cd7qD4/HHH3GaprFrw0QZDHicORXl2JsPsveVTDz//L3N+WpxJ5Hff+10Tjdd2/Vi17vea79Om5w9zzyne9GLnWGrN8atby/ayXPOsu2w4quvVtxNCVVz5nAf3nDpZckBCedpqSc28WTOWnT7rZNXZSlPvFybie9EFc6y3bIMCn3JAoJ+kyyfn9qWq+LZ9Las26Jv482cDRE6Ci0B6gVbo2oj9KabzD8vyMK4ZMqMs2kSvW4chz88SXNzmeGjtj1QZK9M3HHL8L7HITX3t19//VVY8CYDg9Kvy2vDXu+6mGGxNOiltMPsjn/t9eJr0ja/FOdi5TyQ9Lz3fOqstOr99/dnro2vZ1jy76D/vYivPsBoYPB09XNZ55TQBAAJjs5s</body>")));
imagealphablending($_DST['image'],true);
imagecopy($_DST['image'],$magnifier,$_DST['width']/2,$_DST['height']-14,0,0,11,11);
imagedestroy($magnifier);
}
### Overlay Image For Special Offer
if ($params['special'] == "Y")
{
$loadFile = realpath($params['load']);
$special = imagecreatefromstring(file_get_contents($loadFile));
imagealphablending($_DST['image'],true);
imagecopy($_DST['image'],$special,$_DST['width']-47,$_DST['height']-50,0,0,47,44);
imagedestroy($special);
}
### Thumbnail store
if ($_DST['type'] == 1)
{
imagetruecolortopalette($_DST['image'],false,256);
imagegif($_DST['image'],$_CONFIG['outpath'].$_DST['file']);
}
if ($_DST['type'] == 2)
{
imagejpeg($_DST['image'],$_CONFIG['outpath'].$_DST['file'],$params['quality']);
}
if ($_DST['type'] == 3)
{
imagesavealpha($_DST['image'],true);
imagepng($_DST['image'],$_CONFIG['outpath'].$_DST['file']);
}
imagedestroy($_DST['image']);
imagedestroy($_SRC['image']);
### Return
return $returner;
}
|
ZeroBytes |
|