location ~ /upload/{
if ($request_uri ~* ^/upload/(.+)_(\d+)x(\d+)\.(jpg|png|gif)$) {
set $src $1;
set $w $2;
set $h $3;
set $t $4;
rewrite . /resize?src=$src&w=$w&h=$h&type=$t break;
}
proxy_pass http://127.0.0.1:3000;
}
app.get('/resize',function(req,res){
var src = req.query.src,
width = req.query.w,
height = req.query.h,
type = req.query.type;
var imgFile = uploadDir+src+'.'+type;
var notFound = '不好意思,该图片不存在或已被删除!';
var thumb = getThumbImg(src,width,height,type);
if(isFileExists(imgFile)){
if(isFileExists(thumb)){
res.type(type).sendFile(__dirname+'/'+thumb);
}else{
imgResize(imgFile,thumb,width,height,type,res);
}
}else{
res.status(404).send(notFound);
}
});
function imgResize(f,th,w,h,t,r){
var imgSize = sizeOf(f);
if(!w||!h||w>=imgSize.width||h>=imgSize.height){
r.type(t).sendFile(__dirname+'/'+f);
}else{
imageMagick(f)
.resize(w,h,'!')
.stream(function(err, stdout, stderr) {
if (err) {
console.log(err);
res.end();
}
var ws = fs.createWriteStream(th);
stdout.pipe(ws);
r.type(t);
stdout.pipe(r);
});
}
}
function isFileExists(filePath){
var bool = !0;
try{
fs.accessSync(filePath,fs.constants.F_OK);
}catch(err){
bool = !1;
}
return bool;
}
app.get(/^\/upload\/(.+)_(\d+)x(\d+)\.(jpg|png|gif)$/,function(req,res){
var src = RegExp.$1,
width = RegExp.$2,
height = RegExp.$3,
type = RegExp.$4;
var imgFile = uploadDir+src+'.'+type;
var notFound = '不好意思,该图片不存在或已被删除!';
var thumb = getThumbImg(src,width,height,type);
if(isFileExists(imgFile)){
if(isFileExists(thumb)){
res.type(type).sendFile(__dirname+'/'+thumb);
}else{
imgResize(imgFile,thumb,width,height,type,res);
}
}else{
res.status(404).send(notFound);
}
});
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^upload/(.+)_([0-9]+)x([0-9]+)\.(jpg|png|gif)$ resize.php?src=$1&w=$2&h=$3&type=$4 [L]
function getThumbImg($src,$w,$h,$type)
{
global $thumbs;
return $_SERVER['DOCUMENT_ROOT'].$thumbs.$src.'_'.$w.'_'.$h.'.'.$type;
}
function imgResize($f,$th,$w,$h,$t)
{
$imagick = new Imagick();
$imagick->readImage($_SERVER['DOCUMENT_ROOT'].'\\'.$f);
$width = $imagick->getImageWidth();
$height = $imagick->getImageHeight();
if(!$w||!$h||$w>=$width||$h>=$height){
header('Content-Type:image/'.$t);
echo file_get_contents($_SERVER['DOCUMENT_ROOT'].'\\'.$f);
}else{
$imagick->stripImage();
$imagick->cropThumbnailImage($w, $h);
$imagick->writeImage($th);
header('Content-Type:image/'.$t);
echo $imagick->getImageBlob();
$imagick->clear();
$imagick->destroy();
}
}
$uploadDir = "uploads/images/";
$thumbs = "uploads/thumbs/";
$src = $_GET['src'];
$width = $_GET['w'];
$height = $_GET['h'];
$type = $_GET['type'];
$imgFile = $uploadDir.$src.'.'.$type;
$notFound = '不好意思,该图片不存在或已被删除!';
$thumb = getThumbImg($src,$width,$height,$type);
if(file_exists($imgFile)){
if(file_exists($thumb)){
header('Content-Type:image/'.$type);
echo file_get_contents($thumb);
}else{
imgResize($imgFile,$thumb,$width,$height,$type);
}
}else{
header("HTTP/1.0 404 Not Found");
header("status: 404");
echo $notFound;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有