convert 原始图片 -crop widthxheight+x+y 目标图片
imagemagick的convert命令通过crop参数,可以把一幅大图片分成若干块大小一样的图片,同时也可以在大图上截取一块图片来。命令格式为
其中widthxheight是目标图片的尺寸,+x+y是原始图片的坐标点,这两组值至少要出现一组,也可以同时存在。另外该命令也可使用gravity来重新定义坐标系统。关于更多gravity的信息
convert src.jpg -crop 100x100 dest.jpg
假设src.jpg的大小是300x200,执行命令后将得到名为dest-0.jpg、dest-1.jpg...dest-5.jpg
的6张大小为100x100的小图片。注意如果尺寸不是目标图片的整数倍,那么右边缘和下
利用ImageMagicK的convert命令,能很方便的实现图片的放大缩小,可以进行等比例缩放,也能缩放到指定的固定大小。缩放的参数resize,由它来指定缩放后图片的宽高,比如“200×100”。
- 等比缩放 例如把图片a.jpg缩放到200×100的尺寸,可以用命令:
convert -resize 200x100 src.jpg dest.jpg
http://www.netingcn.com/category/imagemagick
下面是我自己写的类
<?php
class imagemagick{
function new_name($filename){
$ext = pathinfo($filename);
$ext = strtolower($ext['extension']);
if ($ext=='jpg'||$ext=='gif'||$ext=='png')
{
$name = basename($filename,$ext);
$name = md5($name.time()).'.'.$ext;
return $name;
}
else
{
return;
}
}
//图片类型
function findImgType($file) {
$img_arr = stristr($file,'.');
$type = explode('.',$img_arr);
return end($type);
}
function movefile($oldurl, $newurl){
set_time_limit(0);
$command = "convert ".$oldurl.$newurl;
exec($command);
}
function upFile($size, $oldurl, $newurl){
set_time_limit(0);
$command = "convert ".$oldurl." -resize '".$size."' ".$newurl;
exec($command);
}
//论坛列表页用的缩略图生成方法
function thumb($width,$height, $oldurl,$newurl,$name){
set_time_limit(0);
if(strtolower($this->findImgType($oldurl))=="gif"){
$name = basename($name,".gif");
$name = $name.'.jpg';
$command ="convert ".$oldurl."[0] -resize x".$height." -gravity center -crop ".$width."x".$height."+0+0 ".$newurl.$name;
}
else
{
$command ="convert ".$oldurl." -gravity center -crop ".$width."x".$height."+0+0 ".$newurl."".$name;
}
exec($command);
return $newurl.$name;
}
//标准图
function resizeImage($width,$height, $oldurl,$newurl,$name)
{
set_time_limit(0);
$command = "convert ".$oldurl." -resize '".$width."x".$height.">' ".$newurl."".$name;
//$command = "convert ".$oldurl." -resize ".$width."x ".$height." ".$newurl."".$name;
exec($command);
}
function bbs_resizeImage($width,$oldurl,$newurl)
{
set_time_limit(0);
$command = "convert ".$oldurl." -resize '".$width."x>' ".$newurl;
exec($command);
}
//头像16*16
function touxiang_thumb($width,$height, $oldurl,$newurl,$name)
{
set_time_limit(0);
if(strtolower($this->findImgType($oldurl))=="gif"&&$width=='16'&&$height=='16')
{
$name = basename($name,".gif");
$name = $name.'.jpg';
$command ="convert ".$oldurl."[0] -resize ".$width."x".$height." ".$newurl."".$name;
}
else
{
$command = "convert ".$oldurl." -resize ".$width."x".$height." ".$newurl."".$name;
}
exec($command);
return '/'.$newurl.$name;
}
//头像标准图和大图
function touxiang_resize($width,$height,$x1,$y1,$oldurl,$newurl,$name)
{
$command ="convert ".$oldurl." -crop ".$width."x".$height."+".$x1."+".$y1." ".$newurl."".$name;
exec($command);
return $newurl.$name;
}
function resizeImage2($width,$height, $oldurl,$newurl)
{
set_time_limit(0);
//$command = "convert ".$oldurl." -resize ".$width."x".$height."> ".$newurl."/".$name;
$command = "convert ".$oldurl." -resize ".$width."x".$height." ".$newurl;
$command ="convert ".$oldurl." -resize x".$height." -gravity center -crop ".$width."x".$height."+0+0 ".$newurl;
exec($command);
}
}
?>