ubuntu下nginx配置图片缩放ngx_image_thumb
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了ubuntu下nginx配置图片缩放ngx_image_thumb,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含13431字,纯文字阅读大概需要20分钟。
内容图文
![ubuntu下nginx配置图片缩放ngx_image_thumb](/upload/InfoBanner/zyjiaocheng/945/917244088e014018bcd6f1d9da2832f3.jpg)
<div id="topics">
<div class="post">
<h1 class="postTitle">
<a id="cb_post_title_url" class="postTitle2" href="https://www.cnblogs.com/1995hxt/p/6104659.html">转:Nginx国人开发缩略图模块(ngx_image_thumb)</a>
</h1>
<div class="clear"></div>
<div class="postBody">
<div id="cnblogs_post_body" class="blogpost-body ">
<p>ngx_image_thumb是nginx中用来生成缩略图的模块,生存缩略图的方法很多,之前也写过一篇 《<a title="" href="http://www.aikaiyuan.com/6103.html" data-original-title="">nginx生成缩略图配置</a>》,在github上发现国人开发的一款模块,作者的文档写的很详细,我便照搬过来了。以后将做一个测试.</p>
<p>特性</p>
<p>本nginx模块主要功能是对请求的图片进行缩略/水印处理,支持文字水印和图片水印。支持自定义字体,文字大小,水印透明度,水印位置,判断原图是否是否大于指定尺寸才处理等等</p>
<p><strong>1. 编译方法</strong></p>
<p>编译前请确认您的系统已经安装了libcurl-dev libgd2-dev libpcre-dev 依赖库<br>
1.1 Debian / Ubuntu 系统举例</p>
<p># 如果你没有安装GCC相关环境才需要执行<br>
$ sudo apt-get install build-essential m4 autoconf automake make<br>
$ sudo apt-get install libgd2-noxpm-dev libcurl4-openssl-dev libpcre3-dev</p>
<p>1.2 CentOS /RedHat / Fedora</p>
<p># 请确保已经安装了gcc automake autoconf m4<br>
$ sudo yum install gd-devel pcre-devel libcurl-devel</p>
<p>1.3 FreeBSD / NetBSD / OpenBSD</p>
<p># 不多说了,自己用port 把libcurl-dev libgd2-dev libpcre-dev 装上吧<br>
# 编译前请确保已经安装gcc automake autoconf m4</p>
<p>1.4 Windows</p>
<p># 也支持的,不过要修改的代码太多了,包括Nginx本身,用VC++来编译<br>
# 嫌麻烦可以用cygwin来编译。还是不建议你这么做了,用Unix/Linux操作系统吧。</p>
<p><strong>2. nginx / tengine 安装</strong></p>
<p>选Nginx还是Tengine,您自己看,两者选其一<br>
2.1 下载Tengine</p>
<div><div id="highlighter_349450" class="syntaxhighlighter bash"><div class="toolbar"><span><a href="#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="bash comments"># wget http://tengine.taobao.org/download/tengine-1.4.5.tar.gz</code></div><div class="line number2 index1 alt1"><code class="bash comments"># tar -zxvf tengine-1.4.5.tar.gz</code></div><div class="line number3 index2 alt2"><code class="bash comments"># cd tengine-1.4.5</code></div></div></td></tr></tbody></table></div></div>
<p>2.2 下载Nginx</p>
<div><div id="highlighter_626639" class="syntaxhighlighter bash"><div class="toolbar"><span><a href="#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="bash comments"># wget http://nginx.org/download/nginx-1.4.0.tar.gz</code></div><div class="line number2 index1 alt1"><code class="bash comments"># tar -zxvf nginx-1.4.0.tar.gz</code></div><div class="line number3 index2 alt2"><code class="bash comments"># cd nginx-1.4.0</code></div></div></td></tr></tbody></table></div></div>
<p>2.3 安装模块</p>
<div><div id="highlighter_4048" class="syntaxhighlighter bash"><div class="toolbar"><span><a href="#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="bash comments"># wget https://github.com/3078825/nginx-image/archive/master.zip</code></div><div class="line number2 index1 alt1"><code class="bash comments"># unzip master.zip</code></div><div class="line number3 index2 alt2"><code class="bash comments"># ./configure --add-module=./nginx-image-master</code></div><div class="line number4 index3 alt1"><code class="bash comments"># make</code></div><div class="line number5 index4 alt2"><code class="bash comments"># make install</code></div></div></td></tr></tbody></table></div></div>
<p><strong>3. 配置</strong></p>
<div><div id="highlighter_389146" class="syntaxhighlighter xhtml"><div class="toolbar"><span><a href="#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="xhtml plain">location / {</code></div><div class="line number2 index1 alt1"><code class="xhtml spaces"> </code><code class="xhtml plain">root html;</code></div><div class="line number3 index2 alt2"> </div><div class="line number4 index3 alt1"><code class="xhtml plain">#添加以下配置</code></div><div class="line number5 index4 alt2"><code class="xhtml spaces"> </code><code class="xhtml plain">image on;</code></div><div class="line number6 index5 alt1"><code class="xhtml spaces"> </code><code class="xhtml plain">image_output on;</code></div><div class="line number7 index6 alt2"><code class="xhtml spaces"> </code><code class="xhtml plain">}</code></div></div></td></tr></tbody></table></div></div>
<p><strong>4. 参数</strong></p>
<p>image on/off 是否开启缩略图功能,默认关闭<br>
image_backend on/off 是否开启镜像服务,当开启该功能时,请求目录不存在的图片(判断原图),将自动从镜像服务器地址下载原图<br>
image_backend_server 镜像服务器地址<br>
image_output on/off 是否不生成图片而直接处理后输出 默认off<br>
image_jpeg_quality 75 生成JPEG图片的质量 默认值75<br>
image_water on/off 是否开启水印功能<br>
image_water_type 0/1 水印类型 0:图片水印 1:文字水印<br>
image_water_min 300 300 图片宽度 300 高度 300 的情况才添加水印<br>
image_water_pos 0-9 水印位置 默认值9 0为随机位置,1为顶端居左,2为顶端居中,3为顶端居右,4为中部居左,5为中部居中,6为中部居右,7为底端居左,8为底端居中,9为底端居右<br>
image_water_file 水印文件(jpg/png/gif),绝对路径或者相对路径的水印图片<br>
image_water_transparent 水印透明度,默认20<br>
image_water_text 水印文字 “Power By Vampire”<br>
image_water_font_size 水印大小 默认 5<br>
image_water_font 文字水印字体文件路径<br>
image_water_color 水印文字颜色,默认 #000000</p>
<p>调用说明</p>
<p>这里假设你的nginx 访问地址为 http://127.0.0.1/</p>
<p>并在nginx网站根目录存在一个 test.jpg 的图片</p>
<p>通过访问</p>
<p>http://127.0.0.1/test.jpg!c300x200.jpg 将会 生成/输出 test.jpg 300×200 的缩略图</p>
<p>其中 c 是生成图片缩略图的参数, 300 是生成缩略图的 宽度 200 是生成缩略图的 高度</p>
<p>一共可以生成四种不同类型的缩略图。</p>
<p>支持 jpeg / png / gif (Gif生成后变成静态图片)</p>
<p>C 参数按请求宽高比例从图片高度 10% 处开始截取图片,然后缩放/放大到指定尺寸( 图片缩略图大小等于请求的宽高 )</p>
<p>M 参数按请求宽高比例居中截图图片,然后缩放/放大到指定尺寸( 图片缩略图大小等于请求的宽高 )</p>
<p>T 参数按请求宽高比例按比例缩放/放大到指定尺寸( 图片缩略图大小可能小于请求的宽高 )</p>
<p>W 参数按请求宽高比例缩放/放大到指定尺寸,空白处填充白色背景颜色( 图片缩略图大小等于请求的宽高 )</p>
<p><strong>5. 调用举例</strong></p>
<p>http://127.0.0.1/test.jpg!c300x300.jpg</p>
<p>http://127.0.0.1/test.jpg!t300x300.jpg</p>
<p>http://127.0.0.1/test.jpg!m300x300.jpg</p>
<p>http://127.0.0.1/test.jpg!w300x300.jpg</p>
<p>http://127.0.0.1/test.c300x300.jpg</p>
<p>http://127.0.0.1/test.t300x300.jpg</p>
<p>http://127.0.0.1/test.m300x300.jpg</p>
<p>http://127.0.0.1/test.w300x300.jpg</p>
<p><strong>6. 最后</strong></p>
<p>这款模块的缩略图是实时生成的,如果你的网站流量比较大,势必会造成nginx服务器负载过高,针对这个问题,你可以参考我们运维生存时间之前写的几篇文章,分别为存硬盘和redis. 《<a title="" href="http://www.aikaiyuan.com/6106.html" data-original-title="">nginx实时生成缩略图到硬盘上</a>》《<a title="" href="http://www.aikaiyuan.com/6109.html" data-original-title="">srcache_nginx+redis构建缓存系统</a>》</p>
<p>参考文章</p>
<p>项目地址:<a title="" href="https://github.com/3078825/nginx-image/blob/master/README_EN.md" rel="external nofollow" data-original-title="">https://github.com/3078825/nginx-image/</a></p>
<div id="wp_rp_first" class="wp_rp_wrap wp_rp_plain">
<div class="wp_rp_content">
<h3 class="related_post_title">相关文章</h3>
<ul class="related_post wp_rp">
<li data-position="0" data-poid="in-6078" data-post-type="none"><a class="wp_rp_title" title="" href="http://www.aikaiyuan.com/6078.html" data-original-title="">nginx实时记录请求状态信息( ngx_realtime_request_module)</a></li>
<li data-position="1" data-poid="in-6446" data-post-type="none"><a class="wp_rp_title" title="" href="http://www.aikaiyuan.com/6446.html" data-original-title="">nginx获取大文件MD5值(nginx模块ngx_file_md5)</a></li>
<li data-position="2" data-poid="in-6002" data-post-type="none"><a class="wp_rp_title" title="" href="http://www.aikaiyuan.com/6002.html" data-original-title="">nginx统计响应的http状态码信息(ngx-http-status-code-counter)</a></li>
<li data-position="3" data-poid="in-3252" data-post-type="none"><a class="wp_rp_title" title="" href="http://www.aikaiyuan.com/3252.html" data-original-title="">nginx自定义模块编写-实时统计模块</a></li>
<li data-position="4" data-poid="in-6106" data-post-type="none"><a class="wp_rp_title" title="" href="http://www.aikaiyuan.com/6106.html" data-original-title="">nginx实时生成缩略图到硬盘上</a></li>
<li data-position="5" data-poid="in-6103" data-post-type="none"><a class="wp_rp_title" title="" href="http://www.aikaiyuan.com/6103.html" data-original-title="">nginx生成缩略图配置</a></li>
</ul>
</div>
</div>
<p>转载请注明:<a title="" href="http://www.aikaiyuan.com" data-original-title="">爱开源</a> » <a title="" href="http://www.aikaiyuan.com/6095.html" data-original-title="">Nginx国人开发缩略图模块(ngx_image_thumb)</a></p>
<p> </p>
</div>
<div id="MySignature"></div>
<div class="clear"></div>
<div id="blog_post_info_block"><div id="BlogPostCategory">
分类:
<a href="https://www.cnblogs.com/1995hxt/category/921709.html" target="_blank">nginx </a></div>
<div id="blog_post_info">
<div id="green_channel">
<a href="javascript:void(0);" id="green_channel_digg" onclick="DiggIt(6104659,cb_blogId,1);green_channel_success(this,'谢谢推荐!');">好文要顶</a>
<a id="green_channel_follow" onclick="follow('c754599a-f5cb-e411-b908-9dcfd8948a71');" href="javascript:void(0);">关注我</a>
<a id="green_channel_favorite" onclick="AddToWz(cb_entryId);return false;" href="javascript:void(0);">收藏该文</a>
<a id="green_channel_weibo" href="javascript:void(0);" title="分享至新浪微博" onclick="ShareToTsina()"><img src="https://common.cnblogs.com/images/icon_weibo_24.png" alt=""></a>
<a id="green_channel_wechat" href="javascript:void(0);" title="分享至微信" onclick="shareOnWechat()"><img src="https://common.cnblogs.com/images/wechat.png" alt=""></a>
</div>
<div id="author_profile">
<div id="author_profile_info" class="author_profile_info">
<div id="author_profile_detail" class="author_profile_info">
<a href="https://home.cnblogs.com/u/1995hxt/">月是故乡明95</a><br>
<a href="https://home.cnblogs.com/u/1995hxt/followees/">关注 - 8</a><br>
<a href="https://home.cnblogs.com/u/1995hxt/followers/">粉丝 - 15</a>
</div>
</div>
<div class="clear"></div>
<div id="author_profile_honor"></div>
<div id="author_profile_follow">
<a href="javascript:void(0);" onclick="follow('c754599a-f5cb-e411-b908-9dcfd8948a71');return false;">+加关注</a>
</div>
</div>
<div id="div_digg">
<div class="diggit" onclick="votePost(6104659,'Digg')">
<span class="diggnum" id="digg_count">0</span>
</div>
<div class="buryit" onclick="votePost(6104659,'Bury')">
<span class="burynum" id="bury_count">0</span>
</div>
<div class="clear"></div>
<div class="diggword" id="digg_tips">
</div>
</div>
<script type="text/javascript">
currentDiggType = 0;
</script></div>
<div class="clear"></div>
<div id="post_next_prev">
<a href="https://www.cnblogs.com/1995hxt/p/6104652.html" class="p_n_p_prefix">« </a> 上一篇: <a href="https://www.cnblogs.com/1995hxt/p/6104652.html" title="发布于 2016-11-26 16:59">转:安装成功的nginx如何添加未编译安装模块</a>
<br>
<a href="https://www.cnblogs.com/1995hxt/p/6105793.html" class="p_n_p_prefix">» </a> 下一篇: <a href="https://www.cnblogs.com/1995hxt/p/6105793.html" title="发布于 2016-11-27 00:32">nginx实时生成缩略图到硬盘上</a>
</div>
</div>
</div>
<div class="postDesc">posted @
<span id="post-date">2016-11-26 17:00</span>
<a href="https://www.cnblogs.com/1995hxt/">月是故乡明95</a>
阅读(<span id="post_view_count">1964</span>)
评论(<span id="post_comment_count">0</span>)
<a href="https://i.cnblogs.com/EditPosts.aspx?postid=6104659" rel="nofollow">
编辑
</a>
<a href="javascript:void(0)" onclick="AddToWz(6104659);return false;">收藏</a></div>
</div>
</div>
内容总结
以上是互联网集市为您收集整理的ubuntu下nginx配置图片缩放ngx_image_thumb全部内容,希望文章能够帮你解决ubuntu下nginx配置图片缩放ngx_image_thumb所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。