手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表Tag:thumb

推荐小程序:TimThumb – PHP Image Resizer

这是一个单文件处理缩略图的程序,直接引用生成缩略图。有点意思,主要是方便啦 .。

官方地址是:http://www.binarymoon.co.uk/projects/timthumb/
文件也很小,只有一点点大,更关键的是可以缓存回来。也能取远程的图片,也可以设置allow的安全站点,这样就相对安全一点了,官方这么介绍 :
TimThumb is a simple, flexible, PHP script that resizes images. You give it a bunch of parameters, and it spits out a thumbnail image that you can display on your site.

TimThumb has seen a massive amount of use across the WordPress world, and a few months after we released it, I took over development from Tim, a friend of Darren Hoyts, who created the original script. Since I took over there have been a whole host of changes, bug fixes, and additions.

I set up this page to act as an archive/ resource, showing the best documentation and demos available for TimThumb. If you have any TimThumb related articles then please feel free to send them over to me so that I can add them to the list.

功能也相对比较方便,用法也很简单,官方现成就举了一些例子,并通过这些例子介绍了它的参数:

How to use TimThumb

看了上面的使用方法,再看看,这个,你就知道很多常见的方法和用法了:

stands for values What it does
src source url to image Tells TimThumb which image to resize › tutorial
w width the width to resize to Remove the width to scale proportionally (will then need the height) › tutorial
h height the height to resize to Remove the height to scale proportionally (will then need the width) › tutorial
q quality 0 - 100 Compression quality. The higher the number the nicer the image will look. I wouldn't recommend going any higher than about 95 else the image will get too large › tutorial
a alignment c, t, l, r, b, tl, tr, bl, br Crop alignment. c = center, t = top, b = bottom, r = right, l = left. The positions can be joined to create diagonal positions › tutorial
zc zoom / crop 0, 1, 2, 3 Change the cropping and scaling settings › tutorial
f filters too many to mention Let's you apply image filters to change the resized picture. For instance you can change brightness/ contrast or even blur the image › tutorial
s sharpen   Apply a sharpen filter to the image, makes scaled down images look a little crisper › tutorial
cc canvas colour hexadecimal colour value (#ffffff) Change background colour. Most used when changing the zoom and crop settings, which in turn can add borders to the image.
ct canvas transparency true (1) Use transparency and ignore background colour

参数很简单,就是不太好记。。。纠结啊

不过用起来的话,是真心简单

 

Tags: thumb

linux命令行抓取网页快照 -(xvfb+CutyCapt)

一直以来对于网页缩图,我都是想着用网上现成的工具来解决,网上也有很多网站提供类似服务,其实我也想做这样的功能,但PHP默认的功能只在windows下面才有,系统有一个默认的函数支持网页缩图的。
网上找了找资料,发现linux server下也可以达到这个效果。嗯,是利用xvfb模拟x server,然后利用cutycapt(一款利用qt框架开发的截屏程序)截图,可以存成PNG和JPG等多种格式的图片。

方法有点简单,我是说在ubuntu下面。直接:

XML/HTML代码
  1. apt-get update  
  2. apt-get install xvfb  
  3. apt-get install subversion libqt4-webkit libqt4-dev g++  
  4. svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt  
  5. cd cutycapt/CutyCapt  
  6. qmake  
  7. make  

操作完后就可以调用命令行截图了。

XML/HTML代码
  1. xvfb-run --server-args="-screen 0, 1024x768x24" ./CutyCapt --url=http://www.zol.com.cn --out=test.png  

截下来你会发现,图片中的中文是乱码,就象这张<<-点击看大图
然后安装中文字体,最简单的办法就是从windows拷一些ttf的文字到/usr/share/fonts/truetype/目录下。
然后再截图就是现在这样

参考:http://blog.saymoon.com/2009/11/take-snapshot-in-linux-command-line/

PS:过段时间可以尝试考虑用接口+队列,生成相应的命令,然后用shell调用命令行。逐步运行,生成缩图,只是生成的缩图都较大,不敢自己做这样服务,硬盘估计很容易就会满了。

我在VPS上面无法运行xvfb,可能是虚拟机不支持x-server模拟?妖了。。。

Tags: linux, 快照, thumb, xvfb, cutycapt