-
近期文章
近期评论
- Oracle 存储过程中发送邮件,并支持用户验证、中文标题和内容 | 隔叶黄莺 Yanbin Blog - 软件编程实践 发表在《用telnet发邮件(支持smtp认证)》
- 网遐 发表在《如何让外网访问小米路由器的硬盘文件》
- 贝贝爸 发表在《服务器安装推荐》
- Python 发送邮件 | 麦叶 发表在《简单的python smtp发邮件代码》
- ahuang007 发表在《简单的python smtp发邮件代码》
分类
归档
其他操作
首页链接
L2TP 一键安装包的一个小bug
使用l2tp的一键安装包在linode上安装vpn发现一个错误,需要将
wget http://www.openswan.org/download/openswan-2.6.24.tar.gz
tar zxvf openswan-2.6.24.tar.gz
cd openswan-2.6.24
改为
wget –no-check-certificate http://www.openswan.org/download/openswan-2.6.37.tar.gz
tar zxvf openswan-2.6.37.tar.gz
cd openswan-2.6.37
其实也不能算bug,文件不在了而已,,另外可以分段执行看结果,或者看出错信息,找问题。
不用ngg gallery显示singlepic图片
一个wordpress用了ngg相册,大概有2万张图片,速度慢的不行,关掉了ngg,速度就正常了,于是写了段代码,兼容ngg gallery的singlepic写法,能正常显示图片,网站速度恢复正常。
莫名其妙的插件,怎么能把速度搞这么慢。这段代码可以用作NextGEN Gallery停用后的一个解决方案
[code lang=”php”]
<?php
/*
Plugin Name: fcuk ngg gallery
Plugin URI: http://www.juyimeng.com
Description: display pic without ngg
Author: juhui
Version: 1.0
Author URI: http://www.juyimeng.com/
*/
function ngg_pic_replacer($content) {
$search = "@\\[singlepic id=(?P<id>\d+)(\s+w=(?P<width>\d+))?(\s+h=(?P<height>\d+))?(\s+float=(?P<float>\w+))?\]@i";
$content= preg_replace_callback( $search, replace_picture , $content,-1);
return $content;
}
function replace_picture($matches) {
global $post, $wpdb;
$picture_id = $matches[‘id’];
$sql="SELECT * FROM {$wpdb->prefix}ngg_pictures p left join {$wpdb->prefix}ngg_gallery g on p.galleryid=g.gid WHERE p.pid = ".
intval( $picture_id ) . " ORDER BY sortorder, pid ASC";
$ngg_image = $wpdb->get_row( $sql );
$append="";
if ($matches[‘width’]) $append.=" width=".$matches[‘width’];
if ($matches[‘height’]) $append.=" height=".$matches[‘height’];
if ($matches[‘float’]) $append.=" align=".$matches[‘float’];
return "<a href=\"/".$ngg_image->path."/".$ngg_image->filename."\"><img class=\"alignnone size-full\" alt=\"image\" ".$append.
" src=\"/".$ngg_image->path."/thumbs/thumbs_".$ngg_image->filename."\"/></a>";
}
add_filter(‘the_content’, ‘ngg_pic_replacer’);
add_filter(‘the_excerpt’, ‘ngg_pic_replacer’);
?>
[/code]
部分代码有问题,我是否要发布到wordpress上呢?
linux下使用imagemagick批量生成缩略图的python脚本
linux下使用imagemagick批量生成缩略图的python脚本。程序用了递归,可以查找目录下所有的图片按照一定的规则生成指定宽度的缩略图。
[code lang=”python”]#!/usr/bin/env python
# -*- coding:utf-8 -*-
#批量resize当前目录下的图片,linux测试过。
#使用imagemagick
import os, sys
iswindows = ‘win32’ in sys.platform.lower() or ‘win64’ in sys.platform.lower()
isosx = ‘darwin’ in sys.platform.lower()
def convert(dirname, size=’400*400′):
for filename in os.listdir(dirname):
if "thumbs" in filename or "cache" in filename:
continue
filename = os.path.join(dirname, filename)
if os.path.isdir(filename):
convert(filename, size)
elif filename.lower().endswith("jpg"):
tname=filename.rsplit(‘/’,1)
thumb_filename= "%s%s%s" % (tname[0],"/thumbs/thumbs_",tname[1])
cmd = "/usr/local/imagemagick/bin/convert \"%s\" -resize %s \"%s\"" % (filename, size, thumb_filename)
print "process.", filename
#print cmd
os.system(cmd)
if __name__ == "__main__":
if len(sys.argv) >= 2:
size = sys.argv[1]
else:
size = "400"
#convert 当前目录下的所有图片
convert(‘.’, size)
[/code]



















