mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-01 05:55:02 +03:00
This commit is contained in:
parent
6c83bad0e0
commit
fcc206a849
|
@ -182,178 +182,6 @@ function func_header_location($sLocation) {
|
|||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Рейсайзинг картинок
|
||||
*
|
||||
* @param unknown_type $sFileSrc
|
||||
* @param unknown_type $sDirDest
|
||||
* @param unknown_type $sFileDest
|
||||
* @param unknown_type $iWidthMax
|
||||
* @param unknown_type $iHeightMax
|
||||
* @param unknown_type $iWidthDest
|
||||
* @param unknown_type $iHeightDest
|
||||
* @param unknown_type $bForcedMinSize
|
||||
* @return unknown
|
||||
*/
|
||||
function func_img_resize($sFileSrc,$sDirDest,$sFileDest,$iWidthMax,$iHeightMax,$iWidthDest=null,$iHeightDest=null,$bForcedMinSize=true) {
|
||||
/**
|
||||
if (!($aSize=getimagesize($sFileSrc))) {
|
||||
return false;
|
||||
}
|
||||
$img_src=false;
|
||||
switch ($aSize['mime']) {
|
||||
case 'image/png':
|
||||
$img_src=imagecreatefrompng($sFileSrc);
|
||||
$sFileDest.='.png';
|
||||
break;
|
||||
case 'image/gif':
|
||||
$img_src=imagecreatefromgif($sFileSrc);
|
||||
$sFileDest.='.gif';
|
||||
break;
|
||||
case 'image/jpeg':
|
||||
$img_src=imagecreatefromjpeg($sFileSrc);
|
||||
$sFileDest.='.jpg';
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
if (!$img_src) {
|
||||
return false;
|
||||
}
|
||||
if (($aSize[0]>$iWidthMax) or ($aSize[1]>$iHeightMax)) {
|
||||
return false;
|
||||
}
|
||||
if ($iWidthDest) {
|
||||
if (!$bForcedMinSize and ($iWidthDest>$aSize[0])) {
|
||||
$iWidthDest=$aSize[0];
|
||||
}
|
||||
$iWidthNew=$iWidthDest;
|
||||
if ($iHeightDest) {
|
||||
$iHeightNew=$iHeightDest;
|
||||
} else {
|
||||
$iSizeRelation=$iWidthDest/$aSize[0];
|
||||
$iHeightNew=round($iSizeRelation*$aSize[1]);
|
||||
}
|
||||
} else {
|
||||
$iWidthNew=$aSize[0];
|
||||
$iHeightNew=$aSize[1];
|
||||
}
|
||||
|
||||
$sFileFullPath=Config::Get('path.root.server').'/'.$sDirDest.'/'.$sFileDest;
|
||||
@func_mkdir(Config::Get('path.root.server'),$sDirDest);
|
||||
if ($iWidthDest and $iWidthDest!=$aSize[0]) {
|
||||
$img_dest=imagecreatetruecolor($iWidthNew,$iHeightNew);
|
||||
imagesavealpha($img_dest,true);
|
||||
imagealphablending($img_dest,false);
|
||||
if (imagecopyresampled($img_dest,$img_src,0,0,0,0,$iWidthNew,$iHeightNew,$aSize[0],$aSize[1])) {
|
||||
imagedestroy($img_src);
|
||||
switch ($aSize['mime']) {
|
||||
case 'image/png':
|
||||
if (imagepng($img_dest,$sFileFullPath)) {
|
||||
chmod($sFileFullPath,0666);
|
||||
return $sFileDest;
|
||||
}
|
||||
break;
|
||||
case 'image/gif':
|
||||
if (imagegif($img_dest,$sFileFullPath)) {
|
||||
chmod($sFileFullPath,0666);
|
||||
return $sFileDest;
|
||||
}
|
||||
break;
|
||||
case 'image/jpeg':
|
||||
if (imagejpeg($img_dest,$sFileFullPath)) {
|
||||
chmod($sFileFullPath,0666);
|
||||
return $sFileDest;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (copy($sFileSrc,$sFileFullPath)) {
|
||||
chmod($sFileFullPath,0666);
|
||||
return $sFileDest;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
**/
|
||||
require_once Config::Get('path.root.engine').'/lib/external/LiveImage/Image.php';
|
||||
$oImage=new LiveImage($sFileSrc);
|
||||
|
||||
if($oImage->get_last_error()){
|
||||
return false;
|
||||
}
|
||||
$sFileDest.='.'.$oImage->get_image_params('format');
|
||||
if (($oImage->get_image_params('width')>$iWidthMax)
|
||||
or ($oImage->get_image_params('height')>$iHeightMax)) {
|
||||
return false;
|
||||
}
|
||||
$sFileFullPath=Config::Get('path.root.server').'/'.$sDirDest.'/'.$sFileDest;
|
||||
@func_mkdir(Config::Get('path.root.server'),$sDirDest);
|
||||
|
||||
if ($iWidthDest) {
|
||||
if (!$bForcedMinSize and ($iWidthDest>$oImage->get_image_params('width'))) {
|
||||
$iWidthDest=$oImage->get_image_params('width');
|
||||
}
|
||||
/**
|
||||
* Ресайзим и выводим результат в файл.
|
||||
* Если не задана новая высота, то применяем масштабирование.
|
||||
* Если нужно добавить Watermark, то запрещаем ручное управление alfa-каналом
|
||||
*/
|
||||
$oImage->resize($iWidthDest,$iHeightDest,(!$iHeightDest),(!Config::Get('module.image.default.watermark_use')));
|
||||
|
||||
/**
|
||||
* Добавляем watermark согласно в конфигурации заданым параметрам
|
||||
*/
|
||||
if(Config::Get('module.image.default.default.watermark_use')) {
|
||||
switch(Config::Get('module.image.default.watermark_type')) {
|
||||
default:
|
||||
case 'text':
|
||||
$oImage->set_font(
|
||||
Config::Get('module.image.default.watermark_font_size'), 0,
|
||||
Config::Get('module.image.default.path.fonts').Config::Get('module.image.default.watermark_font').'.ttf'
|
||||
);
|
||||
|
||||
$oImage->watermark(
|
||||
Config::Get('module.image.default.watermark_text'),
|
||||
explode(',',Config::Get('module.image.default.watermark_position'),2),
|
||||
explode(',',Config::Get('module.image.default.watermark_font_color')),
|
||||
explode(',',Config::Get('module.image.default.watermark_back_color')),
|
||||
Config::Get('module.image.default.watermark_font_alfa'),
|
||||
Config::Get('module.image.default.watermark_back_alfa')
|
||||
);
|
||||
break;
|
||||
case 'image':
|
||||
$oImage->paste_image(
|
||||
Config::Get('module.image.default.path.watermarks').Config::Get('module.image.default.watermark_image'),
|
||||
true, explode(',',Config::Get('module.image.default.watermark_position'),2)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Скругляем углы
|
||||
*/
|
||||
if(Config::Get('module.image.default.round_corner')) {
|
||||
$oImage->round_corners(
|
||||
Config::Get('module.image.default.round_corner_radius'),
|
||||
Config::Get('module.image.default.round_corner_rate')
|
||||
);
|
||||
}
|
||||
|
||||
$oImage->output(null,$sFileFullPath);
|
||||
|
||||
chmod($sFileFullPath,0666);
|
||||
return $sFileDest;
|
||||
} elseif (copy($sFileSrc,$sFileFullPath)) {
|
||||
chmod($sFileFullPath,0666);
|
||||
return $sFileDest;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Создаёт каталог по полному пути
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue