察看文件系统状况实用命令
Posted in Linux/Apache on 2007/11/27 / 评论(0) »
察看根目录下每个目录总的文件大小:
du -sm /*
察看分区状况:
df -h
du -sm /*
察看分区状况:
df -h
Here is my code after I study Imagick, thanks to Mikko Koppanen.
<?php
$logo = new Imagick("logo.gif");
replaceOneColorOfImage($logo,"#025AA4",'transparent');
$logo_width = $logo->getImageWidth();
$logo_height = $logo->getImageHeight();
$im = new Imagick("glitter_blue.gif");
$new_im = new Imagick();
$new_im->setFormat("gif");
foreach ($im as $image){
repeatPic($new_im,$image,$logo_width,$logo_height);
$new_im->compositeImage($logo,Imagick::COMPOSITE_OVER,0,0);
}
header( "Content-Type: image/gif" );
echo $new_im->getImagesBlob();
die;
/**
* replace one color to another color or transparent
* @param imagick $im
* @param string $color
* @param string $replacecolor
* @return void
*/
function replaceOneColorOfImage(& $im,$color='white',$replacecolor='black'){
$im ->setImageMatte( true );
$color_pix = new ImagickPixel($color);
$it = $im->getPixelIterator();
foreach( $it as $row => $pixels )
{
foreach ( $pixels as $column => $pixel )
{
$color = $pixel->getColorValue (imagick::COLOR_ALPHA );
if($pixel->isSimilar($color_pix,1.732)){
$pixel->setColor( $replacecolor );
//$pixel->setColorValue(imagick::COLOR_OPACITY ,0.3);
}
}
$it->syncIterator();
}
}
/**
* repeat a pic to a big size
* @param imagick $new_im
* @param imagick $image
* @param integer $width
* @param integer $height
* @return void
*/
function repeatPic(&$new_image,$image,$width,$height){
$new_image->newImage($width,$height,new ImagickPixel("transparent"));
$org_width = $image->getImageWidth();
$org_height = $image->getImageHeight();
for ($i=0,$c=ceil($width%$org_width);$i<=$c;$i++){
for ($j=0,$cc=ceil($height%$org_height);$j<=$cc;$j++){
$new_image->compositeImage($image,Imagick::COMPOSITE_OVER,$org_width*$i,$org_height*$j);
}
}
}
?>
New method to achieve, without my function:
$logo = new Imagick("logo.gif");
$logo->paintTransparentImage("#025AA4",0,0);
$logo_width = $logo->getImageWidth();
$logo_height = $logo->getImageHeight();
$im = new Imagick("glitter_blue.gif");
$new_im = new Imagick();
$new_im->setFormat("gif");
foreach ($im as $image){
$tmp =new Imagick();
$tmp->newImage( $logo_width, $logo_height, "transparent", "gif" );
$new_im->addImage( $tmp->textureImage( $image ) );
$new_im->compositeImage( $logo, Imagick::COMPOSITE_OVER, 0, 0 );
}
header( "Content-Type: image/gif" );
echo $new_im->getImagesBlob();
original pic:
http://www.kakapo.cn/imagick/glitter_blue.gif
http://www.kakapo.cn/imagick/logo.gif
example result pic:
<?php
$logo = new Imagick("logo.gif");
replaceOneColorOfImage($logo,"#025AA4",'transparent');
$logo_width = $logo->getImageWidth();
$logo_height = $logo->getImageHeight();
$im = new Imagick("glitter_blue.gif");
$new_im = new Imagick();
$new_im->setFormat("gif");
foreach ($im as $image){
repeatPic($new_im,$image,$logo_width,$logo_height);
$new_im->compositeImage($logo,Imagick::COMPOSITE_OVER,0,0);
}
header( "Content-Type: image/gif" );
echo $new_im->getImagesBlob();
die;
/**
* replace one color to another color or transparent
* @param imagick $im
* @param string $color
* @param string $replacecolor
* @return void
*/
function replaceOneColorOfImage(& $im,$color='white',$replacecolor='black'){
$im ->setImageMatte( true );
$color_pix = new ImagickPixel($color);
$it = $im->getPixelIterator();
foreach( $it as $row => $pixels )
{
foreach ( $pixels as $column => $pixel )
{
$color = $pixel->getColorValue (imagick::COLOR_ALPHA );
if($pixel->isSimilar($color_pix,1.732)){
$pixel->setColor( $replacecolor );
//$pixel->setColorValue(imagick::COLOR_OPACITY ,0.3);
}
}
$it->syncIterator();
}
}
/**
* repeat a pic to a big size
* @param imagick $new_im
* @param imagick $image
* @param integer $width
* @param integer $height
* @return void
*/
function repeatPic(&$new_image,$image,$width,$height){
$new_image->newImage($width,$height,new ImagickPixel("transparent"));
$org_width = $image->getImageWidth();
$org_height = $image->getImageHeight();
for ($i=0,$c=ceil($width%$org_width);$i<=$c;$i++){
for ($j=0,$cc=ceil($height%$org_height);$j<=$cc;$j++){
$new_image->compositeImage($image,Imagick::COMPOSITE_OVER,$org_width*$i,$org_height*$j);
}
}
}
?>
New method to achieve, without my function:
$logo = new Imagick("logo.gif");
$logo->paintTransparentImage("#025AA4",0,0);
$logo_width = $logo->getImageWidth();
$logo_height = $logo->getImageHeight();
$im = new Imagick("glitter_blue.gif");
$new_im = new Imagick();
$new_im->setFormat("gif");
foreach ($im as $image){
$tmp =new Imagick();
$tmp->newImage( $logo_width, $logo_height, "transparent", "gif" );
$new_im->addImage( $tmp->textureImage( $image ) );
$new_im->compositeImage( $logo, Imagick::COMPOSITE_OVER, 0, 0 );
}
header( "Content-Type: image/gif" );
echo $new_im->getImagesBlob();
original pic:
http://www.kakapo.cn/imagick/glitter_blue.gif
http://www.kakapo.cn/imagick/logo.gif
example result pic:
Imagick2.0之后PHP 的官方手册上几乎没有举例,学习起来很困难。在互联网上关于IMagick的使用范例也很少。今天在研究Imagick对中文字体的支持时发现了一个国外的blog:Mikko’s blog,里面有最新的关于Imagick类的使用范例,实在是太好了!
来源:
http://valokuva.org/?cat=1
来源:
http://valokuva.org/?cat=1
imagemagick是一个开源的强大的适用于图形图像开发制作的软件套件,与GD库同等级别的,甚至有些功能是GD所没有的,比如创建动态的gif图片。它基于命令行操作的,但同时为大量的其它编程语言提供了接口。详细请访问官方网站是http://www.imagemagick.org
本文主要介绍imagemagick为php语言提供的两个扩展imagick和MagickWand for PHP的安装。IMagick 已经被php最新的版本选为内部的扩展函数库,php的手册已经有了函数说明使用文档。这个扩展是可选安装的。
imagemagick有两款接口,分别是 MagickWand API 和MagickCore API。MagickCore API 是全面的底层的接口,比较适合高水平的程序员,而MagickWand API 是官方推荐的精选的重要的一些接口。IMagick和MagickWand for PHP就是分别为这两款接口而准备的。
下载地址:
ImageMagick 6.3.6-10 http://sourceforge.net/projects/ImageMagick
IMagick http://pecl.php.net/package/imagick
MagickWand For PHP http://www.magickwand.org/
安装:
无论是安装IMagick或者是MagickWand For PHP都需要先安装ImageMagick。
1.安装ImageMagick
服务器如果没有安装Jpeg v6b、libPng、FreeType 的要在安装imagemagick之前先装好,否则imagemagick没法读取jpeg和png图片,字体文件也读不了。下面是安装Imagemagick时./configure的结果,可以查看imagickMagick是否支持哪些格式的图片以及一些环境配置:
Host system type : i686-pc-linux-gnu
Option Value
-------------------------------------------------------------------------------
Shared libraries --enable-shared=yes yes
Static libraries --enable-static=yes yes
Module support --with-modules=yes yes
GNU ld --with-gnu-ld=yes yes
Quantum depth --with-quantum-depth=16 16
High Dynamic Range Imagery
--enable-hdri=no no
Delegate Configuration:
BZLIB --with-bzlib=yes yes
DJVU --with-djvu=no no
DPS --with-dps=yes no
FlashPIX --with-fpx=yes no
FontConfig --with-fontconfig=no no
FreeType --with-freetype=yes yes(支持)
GhostPCL None pcl6 (unknown)
Ghostscript None gs (7.07)
result_ghostscript_font_dir='none'
Ghostscript fonts --with-gs-font-dir=default
Ghostscript lib --with-gslib=yes no (failed tests)
Graphviz --with-gvc=yes no
JBIG --with-jbig=yes no
JPEG v1 --with-jpeg=yes yes(支持)
JPEG-2000 --with-jp2=yes no
LCMS --with-lcms=yes no
Magick++ --with-magick-plus-plus=yes yes
OpenEXR --with-openexr=yes no
PERL --with-perl=yes /usr/bin/perl
PNG --with-png=yes yes(支持)
RSVG --with-rsvg=no no
TIFF --with-tiff=yes no
result_windows_font_dir='none'
Windows fonts --with-windows-font-dir=
WMF --with-wmf=yes no
X11 --with-x= no
XML --with-xml=no no
ZLIB --with-zlib=yes yes
X11 Configuration:
X_CFLAGS =
X_PRE_LIBS =
X_LIBS =
X_EXTRA_LIBS =
Options used to compile and link:
PREFIX = /usr/local
EXEC-PREFIX = /usr/local
VERSION = 6.3.6
CC = gcc
CFLAGS = -g -O2 -Wall -W -pthread
MAGICK_CFLAGS = -g -O2 -Wall -W -pthread
CPPFLAGS = -I/usr/local/include
PCFLAGS =
DEFS = -DHAVE_CONFIG_H
LDFLAGS =
MAGICK_LDFLAGS = -L/usr/local/lib
LIBS = -lMagick -ljpeg -lbz2 -lz -lm -lpthread
CXX = g++
CXXFLAGS = -g -O2 -Wall -W -pthread
2.安装Imagick
我们采用不需要php源代码的方法,即不需要重新编译php,直接将Imagick源码编译成so扩展。
安装完成后系统会产生一个imagick.so文件,并提示路径如下
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/
这个动态文件可以给相同的php环境使用,比如我直接将imagick.so复制到/opt/lampp/lib/php/exention/extension/no-debug-non-zts-20060613/下,xampp环境就可以使用这个动态扩展了,非常方便;
最后一步需要在php.ini加入extension=imagick.so这行,重启apache.安装完毕。
如果想编译成php的一个静态模块,方法:
3.安装magickwand
我们采用跟imagick相同的方法:
安装完成后系统会产生一个magickwand.so文件,并提示路径如下
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/
最后一步需要在php.ini加入extension=magickwand.so这行,重启apache.安装完毕。
如果想编译成php静态模块:
PHP_SRC_DIR代表机器上的php源代码路径,例如/root/php-5.2.2
最后通过phpinfo去查看安装是否成功,关于使用待续。
本文主要介绍imagemagick为php语言提供的两个扩展imagick和MagickWand for PHP的安装。IMagick 已经被php最新的版本选为内部的扩展函数库,php的手册已经有了函数说明使用文档。这个扩展是可选安装的。
imagemagick有两款接口,分别是 MagickWand API 和MagickCore API。MagickCore API 是全面的底层的接口,比较适合高水平的程序员,而MagickWand API 是官方推荐的精选的重要的一些接口。IMagick和MagickWand for PHP就是分别为这两款接口而准备的。
下载地址:
ImageMagick 6.3.6-10 http://sourceforge.net/projects/ImageMagick
IMagick http://pecl.php.net/package/imagick
MagickWand For PHP http://www.magickwand.org/
安装:
无论是安装IMagick或者是MagickWand For PHP都需要先安装ImageMagick。
1.安装ImageMagick
$tar xzvf ImageMagick-6.3.6-10.tar.gz
$cd ImageMagick-6.3.6
$./configure
$make
$make install
$cd ImageMagick-6.3.6
$./configure
$make
$make install
服务器如果没有安装Jpeg v6b、libPng、FreeType 的要在安装imagemagick之前先装好,否则imagemagick没法读取jpeg和png图片,字体文件也读不了。下面是安装Imagemagick时./configure的结果,可以查看imagickMagick是否支持哪些格式的图片以及一些环境配置:
Host system type : i686-pc-linux-gnu
Option Value
-------------------------------------------------------------------------------
Shared libraries --enable-shared=yes yes
Static libraries --enable-static=yes yes
Module support --with-modules=yes yes
GNU ld --with-gnu-ld=yes yes
Quantum depth --with-quantum-depth=16 16
High Dynamic Range Imagery
--enable-hdri=no no
Delegate Configuration:
BZLIB --with-bzlib=yes yes
DJVU --with-djvu=no no
DPS --with-dps=yes no
FlashPIX --with-fpx=yes no
FontConfig --with-fontconfig=no no
FreeType --with-freetype=yes yes(支持)
GhostPCL None pcl6 (unknown)
Ghostscript None gs (7.07)
result_ghostscript_font_dir='none'
Ghostscript fonts --with-gs-font-dir=default
Ghostscript lib --with-gslib=yes no (failed tests)
Graphviz --with-gvc=yes no
JBIG --with-jbig=yes no
JPEG v1 --with-jpeg=yes yes(支持)
JPEG-2000 --with-jp2=yes no
LCMS --with-lcms=yes no
Magick++ --with-magick-plus-plus=yes yes
OpenEXR --with-openexr=yes no
PERL --with-perl=yes /usr/bin/perl
PNG --with-png=yes yes(支持)
RSVG --with-rsvg=no no
TIFF --with-tiff=yes no
result_windows_font_dir='none'
Windows fonts --with-windows-font-dir=
WMF --with-wmf=yes no
X11 --with-x= no
XML --with-xml=no no
ZLIB --with-zlib=yes yes
X11 Configuration:
X_CFLAGS =
X_PRE_LIBS =
X_LIBS =
X_EXTRA_LIBS =
Options used to compile and link:
PREFIX = /usr/local
EXEC-PREFIX = /usr/local
VERSION = 6.3.6
CC = gcc
CFLAGS = -g -O2 -Wall -W -pthread
MAGICK_CFLAGS = -g -O2 -Wall -W -pthread
CPPFLAGS = -I/usr/local/include
PCFLAGS =
DEFS = -DHAVE_CONFIG_H
LDFLAGS =
MAGICK_LDFLAGS = -L/usr/local/lib
LIBS = -lMagick -ljpeg -lbz2 -lz -lm -lpthread
CXX = g++
CXXFLAGS = -g -O2 -Wall -W -pthread
2.安装Imagick
我们采用不需要php源代码的方法,即不需要重新编译php,直接将Imagick源码编译成so扩展。
$tar xzvf imagick-2.0.1.tgz
$cd imagick-2.0.1
$phpize (此命令前提是你已经安装了php,phpize可以通过whereis命令查找出具体路径)
$./configure
$make
$make install
$cd imagick-2.0.1
$phpize (此命令前提是你已经安装了php,phpize可以通过whereis命令查找出具体路径)
$./configure
$make
$make install
安装完成后系统会产生一个imagick.so文件,并提示路径如下
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/
这个动态文件可以给相同的php环境使用,比如我直接将imagick.so复制到/opt/lampp/lib/php/exention/extension/no-debug-non-zts-20060613/下,xampp环境就可以使用这个动态扩展了,非常方便;
最后一步需要在php.ini加入extension=imagick.so这行,重启apache.安装完毕。
如果想编译成php的一个静态模块,方法:
$tar xzvf imagick-2.0.1.tgz $PHP_SOURCE_DIR/ext/imagick
$rm configure && ./buildconf --force
$./configure (重新编译php,在你其它选项最后加上) --with-imagick
$make && make install
$rm configure && ./buildconf --force
$./configure (重新编译php,在你其它选项最后加上) --with-imagick
$make && make install
3.安装magickwand
我们采用跟imagick相同的方法:
$tar xzvf MagickWandForPHP-1.0.5.tar.gz
$cd MagickWandForPHP-1.0.5
$phpize (此命令前提是你已经安装了php,phpize可以通过whereis命令查找出具体路径)
$./configure
$make
$make install
$cd MagickWandForPHP-1.0.5
$phpize (此命令前提是你已经安装了php,phpize可以通过whereis命令查找出具体路径)
$./configure
$make
$make install
安装完成后系统会产生一个magickwand.so文件,并提示路径如下
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/
最后一步需要在php.ini加入extension=magickwand.so这行,重启apache.安装完毕。
如果想编译成php静态模块:
PHP_SRC_DIR代表机器上的php源代码路径,例如/root/php-5.2.2
$tar xzvf MagickWandForPHP-1.0.5.tar.gz PHP_SRC_DIR/ext/magickwand/
$cd PHP_SRC_DIR/ext/magickwand/
$phpize (此命令前提是你已经安装了php,phpize可以通过whereis命令查找出具体路径)
$cd PHP_SRC_DIR
$rm ./configure
$./buildconf --force
$./configure (重新编译php,在你其它选项最后加上) --with-magickwand=/usr
$cd PHP_SRC_DIR/ext/magickwand/
$phpize (此命令前提是你已经安装了php,phpize可以通过whereis命令查找出具体路径)
$cd PHP_SRC_DIR
$rm ./configure
$./buildconf --force
$./configure (重新编译php,在你其它选项最后加上) --with-magickwand=/usr
最后通过phpinfo去查看安装是否成功,关于使用待续。
个性化域名的实现
Posted in Linux/Apache on 2007/10/16 / 评论(0) »
个性化域名,即将网站用户的用户名作为二级域名的前缀。比如像: http://jonson.kakapo.cn
如何实现这种功能呢?我采用三个步骤来实现:
1、在域名管理网站增加一个A记录,比如:*.kakapo.cn,然后指向一台apache服务器的ip地址。这个叫泛域名解析。
2、在那台apche服务器的主机配置中,在你要实现个性化域名的虚拟主机配置代码中加入一段代码:
ServerAlias kakapo.cn *.kakapo.cn
举例:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>
3、这步是采用url_rewrite规则完成。这个规则可以写在apache的虚拟主机配置里,也可以写在.htaccess里面。
举例代码如下:
RewriteEngine on
RewriteCond %{HTTP_HOST} (?!www|shop|bbs|home|pay|account|admin|cms|image)^[a-z0-9\-]+\.kakapo\.cn$
RewriteRule ^/?$ /%{HTTP_HOST}
RewriteRule ^/([a-z0-9\-]+)\.kakapo\.cn/?$ space/space.php?action=space&view=defaults&uname=$1 [L]






