function file_tumb( $_arrSet=array() ) {
$_strSrc=empty( $_arrSet['src'] )?FILE_TUMB_NOIMAGE: DIR_DBFS.$_arrSet['src'];
$_intFlgCu=empty( $_arrSet['cu'] )?FILE_TUMB_CASHING:$_arrSet['cu'];
$_intFlgMt=empty( $_arrSet['mt'] )?FILE_TUMB_MORPHING:$_arrSet['mt'];
$_intWnew=empty( $_arrSet['w'] )?FILE_TUMB_W:$_arrSet['w'];
$_intHnew=empty( $_arrSet['h'] )?FILE_TUMB_H:$_arrSet['h'];
if ( file_exists( $_strSrc ) ) {
if ( $_intFlgMt==2 ) {
header( 'Content-Type: image/jpeg' );
readfile( $_strSrc );
exit;
}
// calculate new image params
list( $_intW, $_intH, $_intF )=GetImageSize( $_strSrc );
$_intWold=$_intW;
$_intHold=$_intH;
if ( $_intFlgMt==0 ) { // fit size
if ( $_intWnew==0 && $_intHnew!=0 ) {
$_intWnew=(int)( $_intW*( $_intHnew/$_intH ) );
}
if ( $_intHnew==0 && $_intWnew!=0 ) {
$_intHnew=(int)( $_intH*( $_intWnew/$_intW ) );
}
if ( $_intWnew!=0 && $_intWnew<$_intW ) {
$_intH=(int)( $_intH*( $_intWnew/$_intW ) );
$_intW=$_intWnew;
}
if ( $_intHnew!=0 && $_intHnew<$_intH ) {
$_intW=(int)( $_intW*( $_intHnew/$_intH ) );
$_intH=$_intHnew;
}
} elseif ( $_intFlgMt==1 ) { // exact size
$_intW=$_intWnew;
$_intH=$_intHnew;
}
// if use cashe
if ( !empty( $_intFlgCu ) ) {
$_strCasheFile=FILE_TUMB_CPATH.md5( $_strSrc.filemtime( $_strSrc ).$_intW.$_intH ).'.pic';
// check the cashe
if ( 0==FILE_TUMB_CFORCE&&file_exists( $_strCasheFile ) ) {
list( $_intCW, $_intCH, $_intCF )=GetImageSize( $_strCasheFile );
// show image
if ( $_intCW==$_intW&&$_intCH==$_intH&&$_intCF==$_intF ) {
header( 'Content-Type: image/jpeg' );
readfile( $_strCasheFile );
exit;
}
}
// remove old cached images with delete old files
$this->dir_readfiles( $arrFiles, FILE_TUMB_CPATH, 1 );
// save thumbnail to cash
if ( FILE_TUMB_METHOD==1 ) {
$this->gen_thumb_bygd( $hdl, $_strSrc, $_intF, $_intW, $_intH, $_intWold, $_intHold );
@imagejpeg( $hdl, $_strCasheFile, FILE_TUMB_QUALITY );
imagedestroy( $hdl );
} else {
system( '/usr/bin/convert -quality '.FILE_TUMB_QUALITY.' -antialias -geometry '.$_intW.'x'.$_intH.' "'.$_strSrc.'" "'.$_strCasheFile.'"' );
}
// show image
if ( file_exists( $_strCasheFile ) ) {
header( 'Content-Type: image/jpeg' );
readfile( $_strCasheFile );
exit;
}
}
// if create thumb on-the-fly (only through gd_lib)
$this->gen_thumb_bygd( $hdl, $_strSrc, $_intF, $_intW, $_intH, $_intWold, $_intHold );
// show image
header( 'Content-type: image/jpeg' );
@imagejpeg( $hdl );
imagedestroy( $hdl );
exit;
}
$this->_errorcode[]='ERR_FILE_EXISTS';
return false;
}
// generate thumb by gd_lib
function gen_thumb_bygd( &$hdl, $_strSrc, $_intF, $_intW, $_intH, $_intWold, $_intHold ) {
switch ( $_intF ) {
case IMAGETYPE_GIF: $source=@imagecreatefromgif( $_strSrc ); break;
case IMAGETYPE_JPEG: $source=@imagecreatefromjpeg( $_strSrc ); break;
case IMAGETYPE_PNG: $source=@imagecreatefrompng( $_strSrc ); break;
}
$hdl=imageCreateTrueColor( $_intW, $_intH );
imagecopyresampled( $hdl, $source, 0, 0, 0, 0, $_intW, $_intH, $_intWold, $_intHold );
imagedestroy( $source );
if ( !empty( $hdl ) ) {
return true;
}
return false;
}