nginx + image_filter_module + lua 处理图片(缩放、翻转)

        location ~ ^/([^_]+)_(\d+)x(\d+)\.(jpg|jpeg|png|gif)$ {
                set $true_uri /$1.$4;
                set $width $2;
                set $height $3;
                access_by_lua '
                    ngx.req.set_uri(ngx.var.true_uri)
                ';
                #image_filter test;
                image_filter resize $width $height;
                #image_filter rotate 90;
                #image_filter crop 100 100;
        }

演示地址: http://yii.nt00.com/upload/1/532c1704b9306_200x200.png

 

javascript 计算中英混合字符串长度及截取函数

产品的BT需求:当输入框限制最多可输入10个字时,达到的效果为输入框可输入5个汉字加10个字母,中文按1个字计算,英文按0.5个字计算,并且超出长度要自动截断。

String.prototype.mb_len = function(){
	var len = 0;
	for(var i=0;i<this.length;i++){
 		len = len+(this.charCodeAt(i)>255?1:0.5);
	}
	return len;
};
String.prototype.mb_sub = function(start, length){
	var str = "";
	for(var i=start;i<this.length;i++){
 		length = length-(this.charCodeAt(i)>255?1:0.5);
		if(length<0)break;
		str = str+this[i];
	}
	return str;
};