Browse Source

获取资源地方处理

tags/6.1.7
tianya 2 years ago
parent
commit
33718e8d90
2 changed files with 94 additions and 66 deletions
  1. +33
    -11
      src/admin/inc/inc_archives_functions.php
  2. +61
    -55
      src/system/helpers/image.helper.php

+ 33
- 11
src/admin/inc/inc_archives_functions.php View File

@@ -124,15 +124,32 @@ function GetCurContent($body)
$htd->OpenUrl($value);

$itype = $htd->GetHead("content-type");
$itype = substr($value, -4, 4);
if (!preg_match("#\.(jpg|gif|png)#i", $itype)) {
if ($itype == 'image/gif') {
$itype = ".gif";
} else if ($itype == 'image/png') {
$itype = ".png";
} else {
$itype = '.jpg';
}
$isImage = true;
if ($itype == 'image/gif') {
$itype = ".gif";
} else if ($itype == 'image/png') {
$itype = ".png";
} else if($itype == 'video/mp4'){
$itype = ".mp4";
$isImage = false;
} else if (preg_match("#^text#i",$itype)){
$itype = ".txt";
$isImage = false;
} else if ($itype == 'application/zip'){
$itype = ".zip";
$isImage = false;
} else if ($itype == 'application/x-rar-compressed'){
$itype = ".rar";
$isImage = false;
} else if($itype == 'image/jpeg') {
$itype = '.jpg';
} else if($itype == 'image/bmp') {
$itype = '.bmp';
} else if($itype == 'image/svg+xml') {
$itype = '.svg';
$isImage = false;
} else {
continue;
}
$milliSecondN = dd2char($milliSecond.mt_rand(1000, 8000));
$value = trim($value);
@@ -141,7 +158,10 @@ function GetCurContent($body)
$rs = $htd->SaveToBin($rndFileName);
if ($rs) {
$info = '';
$imginfos = GetImageSize($rndFileName, $info);
$imginfos = array(0,0);
if ($isImage) {
$imginfos = GetImageSize($rndFileName, $info);
}
$fsize = filesize($rndFileName);
//保存图片附件信息
$inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)
@@ -153,7 +173,9 @@ function GetCurContent($body)
$fileurl = $cfg_basehost.$fileurl;
}
$body = str_replace($value, $fileurl, $body);
@WaterImg($rndFileName, 'down');
if ($isImage) {
@WaterImg($rndFileName, 'down');
}
}
}
$htd->Close();


+ 61
- 55
src/system/helpers/image.helper.php View File

@@ -24,72 +24,78 @@ if (!function_exists('ImageResize')) {
function ImageResize($srcFile, $toW, $toH, $toFile = "")
{
global $cfg_photo_type;
if ($toFile == '') $toFile = $srcFile;
$info = '';
$srcInfo = GetImageSize($srcFile, $info);
switch ($srcInfo[2]) {
case 1:
if (!$cfg_photo_type['gif']) return FALSE;
$im = imagecreatefromgif($srcFile);
break;
case 2:
if (!$cfg_photo_type['jpeg']) return FALSE;
$im = imagecreatefromjpeg($srcFile);
break;
case 3:
if (!$cfg_photo_type['png']) return FALSE;
$im = imagecreatefrompng($srcFile);
break;
case 6:
if (!$cfg_photo_type['bmp']) return FALSE;
$im = imagecreatefromwbmp($srcFile);
break;
}
$srcW = ImageSX($im);
$srcH = ImageSY($im);
if ($srcW <= $toW && $srcH <= $toH) return TRUE;
$toWH = $toW / $toH;
$srcWH = $srcW / $srcH;
if ($toWH <= $srcWH) {
$ftoW = $toW;
$ftoH = $ftoW * ($srcH / $srcW);
} else {
$ftoH = $toH;
$ftoW = $ftoH * ($srcW / $srcH);
}
if ($srcW > $toW || $srcH > $toH) {
if (function_exists("imagecreateTRUEcolor")) {
@$ni = imagecreateTRUEcolor($ftoW, $ftoH);
if ($ni) {
imagecopyresampled($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
} else {
$ni = imagecreate($ftoW, $ftoH);
imagecopyresized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
}
} else {
$ni = imagecreate($ftoW, $ftoH);
imagecopyresized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
}
try {
if ($toFile == '') $toFile = $srcFile;
$info = '';
$srcInfo = GetImageSize($srcFile, $info);
switch ($srcInfo[2]) {
case 1:
imagegif($ni, $toFile);
if (!$cfg_photo_type['gif']) return FALSE;
$im = imagecreatefromgif($srcFile);
break;
case 2:
imagejpeg($ni, $toFile, 85);
if (!$cfg_photo_type['jpeg']) return FALSE;
$im = imagecreatefromjpeg($srcFile);
break;
case 3:
imagepng($ni, $toFile);
if (!$cfg_photo_type['png']) return FALSE;
$im = imagecreatefrompng($srcFile);
break;
case 6:
imagebmp($ni, $toFile);
if (!$cfg_photo_type['bmp']) return FALSE;
$im = imagecreatefromwbmp($srcFile);
break;
default:
return FALSE;
}
imagedestroy($ni);
$srcW = ImageSX($im);
$srcH = ImageSY($im);
if ($srcW <= $toW && $srcH <= $toH) return TRUE;
$toWH = $toW / $toH;
$srcWH = $srcW / $srcH;
if ($toWH <= $srcWH) {
$ftoW = $toW;
$ftoH = $ftoW * ($srcH / $srcW);
} else {
$ftoH = $toH;
$ftoW = $ftoH * ($srcW / $srcH);
}
if ($srcW > $toW || $srcH > $toH) {
if (function_exists("imagecreateTRUEcolor")) {
@$ni = imagecreateTRUEcolor($ftoW, $ftoH);
if ($ni) {
imagecopyresampled($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
} else {
$ni = imagecreate($ftoW, $ftoH);
imagecopyresized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
}
} else {
$ni = imagecreate($ftoW, $ftoH);
imagecopyresized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
}
switch ($srcInfo[2]) {
case 1:
imagegif($ni, $toFile);
break;
case 2:
imagejpeg($ni, $toFile, 85);
break;
case 3:
imagepng($ni, $toFile);
break;
case 6:
imagebmp($ni, $toFile);
break;
default:
return FALSE;
}
imagedestroy($ni);
}
imagedestroy($im);
return true;
} catch(Throwable $th) {
return false;
} catch (Exception $e) {
return false;
}
imagedestroy($im);
return TRUE;
}
}
/**


Loading…
Cancel
Save