当前位置: 首页 > news >正文

网站建设毕业论文/最新消息

网站建设毕业论文,最新消息,手机兼职可以做什么,钓鱼平台设计原来图片服务器采用Windows .net架构,鉴于需求需要生成各种尺寸图片。流程说明:用户从Nginx请求对应的图片,判断是否存在_200x300的对应参数,如果没有就直接请求到对应目录的原图,否则继续判断是否在本地已经生成了对应的缓存图片&#xff0c…

原来图片服务器采用Windows .net架构,鉴于需求需要生成各种尺寸图片。

0818b9ca8b590ca3270a3433284dd417.png

流程说明:

用户从Nginx请求对应的图片,判断是否存在_200x300的对应参数,如果没有就直接请求到对应目录的原图,否则继续判断是否在本地已经生成了对应的缓存图片,如果存在返回已经生成过的定制尺寸图片,否则请求PHP动态生成。

Nginx部分配置:

server {

listen       80;

server_name  pics.abc.com;

location / {

root   /var/www/html;

index  index.html index.htm index.php;

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

location ~ \_(\d+)x(\d+)\.(jpg|png|gif|jpeg|bmp)$ {  //判断是否定制图

try_files $uri /temp/$uri /get.php;    //判断是否已生成过定制图否则转交给/get.php

expires      30d;

}

location ~ \.php$ {

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

include        fastcgi_params;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp)$

{

expires      30d;

}

}

}

在/var/www/html我们以只读方式挂载Windows的目录,修改/etc/fstab,添加

\\192.168.2.3\f$\pics.abc.com\pics /var/www/html/pics/ cifs    ro,username=user,password=pass   1  2

然后重启netfs服务,另外执行下面命令,安装依赖的包

yum -y install samba-client cifs-utils

service netfs restart

chkconfig netfs on

生成的缩率图会放到网站目录的temp目录下,如请求的http://pics.abc.com/pics/201604/29/abc_200x300.jpg

则生成的图片放在temp/pics/201604/29/abc_200x300.jpg目录下

PHP脚本:

function thumb($src, $width, $height, $filename, $mode = 'scale', $quality = '100') {

try {

$imageValue = getimagesize($src);

$sourceWidth = $imageValue[0]; //原图宽

$sourceHeight = $imageValue[1]; //原图高

$thumbWidth = $width; //缩略图宽

$thumbHeight = $height; //缩略图高

$_x = 0;

$_y = 0;

$w = $sourceWidth;

$h = $sourceHeight;

if ($mode == 'scale') {

if ($sourceWidth <= $thumbWidth && $sourceHeight <= $thumbHeight) {

$_x = floor(($thumbWidth - $sourceWidth) / 2);

$_y = floor(($thumbHeight - $sourceHeight) / 2);

$thumbWidth = $sourceWidth;

$thumbHeight = $sourceHeight;

} else {

if ($thumbHeight * $sourceWidth > $thumbWidth * $sourceHeight) {

$thumbHeight = floor($sourceHeight * $width / $sourceWidth);

$_y = floor(($height - $thumbHeight) / 2);

} else {

$thumbWidth = floor($sourceWidth * $height / $sourceHeight);

$_x = floor(($width - $thumbWidth) / 2);

}

}

} else if ($mode == 'crop') {

if ($sourceHeight 

$thumbWidth = floor($thumbWidth * $sourceHeight / $thumbHeight);

$thumbHeight = $sourceHeight;

}

if ($sourceWidth 

$thumbHeight = floor($thumbHeight * $sourceWidth / $thumbWidth);

$thumbWidth = $sourceWidth;

}

$s1 = $sourceWidth / $sourceHeight; //原图比例

$s2 = $width / $height; //新图比例

if ($s1 == $s2) {

} else if ($s1 > $s2) { //全高度

$y = 0;

$ax = floor($sourceWidth * ($thumbHeight / $sourceHeight));

$x = ($ax - $thumbWidth) / 2;

$w = $thumbWidth / ($thumbHeight / $sourceHeight);

} else { //全宽度

$x = 0;

$ay = floor($sourceHeight * ($thumbWidth / $sourceWidth)); //模拟原图比例高度

$y = ($ay - $thumbHeight) / 2;

$h = $thumbHeight / ($thumbWidth / $sourceWidth);

}

}

switch ($imageValue[2]) {

case 2: $source = imagecreatefromjpeg($src);

break;

case 1: $source = imagecreatefromgif($src);

break;

case 3: $source = imagecreatefrompng($src);

break;

case 6: $source = imagecreatefromwbmp($src);

break;

default: defulat();

return;

}

header("Content-type: image/jpeg");

$thumb = imagecreatetruecolor($width, $height);

imagefill($thumb, 0, 0, imagecolorallocate($thumb, 255, 255, 255));

imagecopyresampled($thumb, $source, 0, 0, $x, $y, $width, $height, $w, $h);

imagejpeg($thumb, null, $quality);

imagejpeg($thumb, $filename, $quality);

imagedestroy($thumb);

imagedestroy($source);

} catch (Exception $ex) {

defulat();

}

}

function defulat() {

/*

$default_img = realpath('../pictures/nopic.gif');

ob_start();

header('Content-type:image/jpeg');

readfile($default_img);

ob_flush();

flush();

*/

echo 'error';

}

function mkDirs($dir){

if(!is_dir($dir)){

if(!mkDirs(dirname($dir))){

return false;

}

if(!mkdir($dir,0755)){

return false;

}

}

return true;

}

$uri=$_SERVER['REQUEST_URI'];

$image=basename($uri);

$temp='./temp/'.dirname($uri).'/';

$imgpath='.'.dirname($uri).'/';

/*

//检查本地是否存在文件,原图

if(file_exists($temp.$image)){

ob_start();

header('Content-type:image/jpeg');

readfile($temp.$image);

ob_flush();

flush();

exit();

}

*/

//检查生成的图片是否曾经生成过,存在即返回,否则重新生成新图

if(!preg_match('/_(\d+)x(\d+)/', $image, $wh)){

ob_start();

header('Content-type:image/jpeg');

readfile($imgpath.$image);

ob_flush();

flush();

exit();

}

$width = $wh[1];

$height = $wh[2];

$source_img=preg_replace('/_(\d+)x(\d+)/', '', $image);

//对长宽都超过的图片返回原图

if($width>=2000 || $height>=2000){

ob_start();

header('Content-type:image/jpeg');

readfile($imgpath.$source_img);

ob_flush();

flush();

exit();

}

//图片处理

$src=$imgpath.$source_img;

$filename=$temp.$image;

mkDirs($temp);

//thumb(realpath($src), $width, $height, $filename, 'crop', '85');

thumb(realpath($src), $width, $height, $filename, 'crop', '100');

PHP生成尺寸部分参考

http://www.jmfq.cn/news/5281363.html

相关文章:

  • asp网站开发的实训/微信营销案例
  • 福州网站建设方案书/网络服务包括
  • 义乌网站建设联系方式/seo的主要内容
  • 金融投资网站模板/百度免费推广方法
  • 做网站中二级导航链接到一级导航/免费b站推广网站短视频
  • vs哪个版本做网站好/seo免费推广软件
  • 网站建设基本流程视频/青岛seo精灵
  • 政府网站和政务新媒体建设管理/知乎seo优化
  • 做网站代下/上海网站推广排名公司
  • 腾讯云网站建设/简单网页制作
  • 一次性付费做网站/网站推广的10种方法
  • 微网站外链/互联网推广与营销
  • 做去态网站要学java吗/推广有什么好方法
  • 印刷厂网站模板/怎样免费推广自己的网站
  • php学多久可以做网站/企业品牌推广方案
  • 奢侈品b2c电商网站建设/北京网络营销推广外包
  • dw怎么用div css做网站/外贸seo网站
  • 上海门户网站制作/百度收录申请
  • 上海实时新闻/云优化软件
  • 网站建设的基本步骤是哪些/推广下载
  • 漳州做网站建设/seo外包网站
  • 做外贸方面的网站/torrent种子搜索引擎
  • 阿里云建设网站视频/网站搜索引擎优化情况怎么写
  • 南昌微信公众号制作/南山网站seo
  • 淘宝里网站建设公司可以吗/搜索引擎优化策略有哪些
  • 案例剖析网站/关键词优化公司排名榜
  • 帮境外赌场做网站是否有风险/友情链接你会回来感谢我
  • 上海比较好的外包公司/seo费用
  • 辽宁建设工程信息网 招标文件/搜索引擎优化主要包括
  • 项目建设管理 公司 网站/电销外包团队在哪找