From 73b3280e9c2c28047f53e51316291d414966be1d Mon Sep 17 00:00:00 2001 From: CberYellowstone <2844829687@qq.com> Date: Fri, 1 Oct 2021 01:24:39 +0800 Subject: [PATCH] =?UTF-8?q?[+]=E9=80=82=E9=85=8DDanDanPlay=E6=A6=82?= =?UTF-8?q?=E5=BF=B5=E7=89=884.0.4=E8=BF=9C=E7=A8=8B=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9B=20[=E2=86=91]=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E8=AE=BF=E9=97=AE=E7=BC=A9=E7=95=A5=E5=9B=BE?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1/.htaccess | 2 ++ api/v1/api.php | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/api/v1/.htaccess b/api/v1/.htaccess index c12df8d..4db81d8 100755 --- a/api/v1/.htaccess +++ b/api/v1/.htaccess @@ -6,6 +6,8 @@ RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteRule library api.php?action=library RewriteRule playlist api.php?action=gettest RewriteRule current/video api.php?action=clcache +RewriteRule ^image/id/(.*)$ api.php?action=image&id=$1 +RewriteRule ^stream/id/(.*)$ api.php?action=stream&id=$1 RewriteRule ^image/(.*)$ api.php?action=image&id=$1 RewriteRule ^stream/(.*)$ api.php?action=stream&id=$1 RewriteRule ^comment/(.*)$ api.php?action=comment&id=$1 diff --git a/api/v1/api.php b/api/v1/api.php index 65cbc0c..d6a4ae2 100755 --- a/api/v1/api.php +++ b/api/v1/api.php @@ -64,6 +64,7 @@ function mkJsonIndexForFolder($folder_path){ $video_path = $video_information_list['file_path']; $video_parent_path_md5 = md5(getFileName(dirname($video_path),TRUE)); $video_file_md5 = md5(getFileName($video_path)); + $video_path = str_replace($GLOBALS['video_root_path'],'','A:'.$video_path); $video_path = str_replace('/','\\',$video_path); $video_path = str_replace('\\','\\\\',$video_path); //$last_time = readLastTime($each_video_path); @@ -82,16 +83,28 @@ function mkJsonIndexForRoot($root){ echo ("]"); } +function showImg($img){ + $info = getimagesize($img); + $imgExt = image_type_to_extension($info[2], false); //获取文件后缀 + $fun = "imagecreatefrom{$imgExt}"; + $imgInfo = $fun($img); //1.由文件或 URL 创建一个新图象。如:imagecreatefrompng ( string $filename ) + //$mime = $info['mime']; + $mime = image_type_to_mime_type(exif_imagetype($img)); //获取图片的 MIME 类型 + header('Content-Type:'.$mime); + $quality = 100; + if($imgExt == 'png') $quality = 9; //输出质量,JPEG格式(0-100),PNG格式(0-9) + $getImgInfo = "image{$imgExt}"; + $getImgInfo($imgInfo, null, $quality); //2.将图像输出到浏览器或文件。如: imagepng ( resource $image ) + imagedestroy($imgInfo); +} function sendVideoPicFromMD5($md5){ $parent_md5 = explode("-",$md5)[0]; $video_md5 = explode("-",$md5)[1]; if($GLOBALS['able_webp']){ - @ header("Content-Type:image/webp"); - echo (file_get_contents(($GLOBALS['data_path'].'/'.$parent_md5.'/'.$video_md5.'/'.$video_md5.'.webp'))); + showImg(($GLOBALS['data_path'].'/'.$parent_md5.'/'.$video_md5.'/'.$video_md5.'.webp')); } else { - @ header("Content-Type:image/jpeg"); - echo (file_get_contents(($GLOBALS['data_path'].'/'.$parent_md5.'/'.$video_md5.'/'.$video_md5.'.jpg'))); + showImg(($GLOBALS['data_path'].'/'.$parent_md5.'/'.$video_md5.'/'.$video_md5.'.jpg')); } }