图片抓取函数
function manage_img_data($imgUrl){
global $resrootpath;
$size = getimagesize($imgUrl);
preg_match('/width="(\\d+)" height="(\\d+)"/',$size[3],$wh);
$width = $wh[1];
$height = $wh[2];
$imgExt = strrchr($imgUrl,".");//获得后缀
if($imgExt == ".jpg" && $width < 201 && $height < 201){
$sec = explode(" ", microtime());
$micro = explode(".", $sec[0]);
$fileName = $sec[1].substr($micro[1], 0, 3);
//$fileName = time();//命名
$filePath = substr($fileName,-4,2).'/'.substr($fileName,-2,2).'/';
$imgNames = $fileName.$imgExt;
ob_start();
readfile($imgUrl);//读入缓存
$ob_img = ob_get_contents();//取出缓存
ob_end_clean(); //清空
$abspath = $resrootpath."images/wiki/";
$picpath = $abspath.$filePath.$imgNames;
//$thp = "/www/webroot/wappp/3g/plugins/movie/images/".$filePath.$imgNames;//$filePath
$createFile=@fopen($picpath, "a");
if($createFile != false){
fwrite($createFile,$ob_img);
fclose($createFile);
$rsyncpath = "images/wiki/".$filePath;
$cmd = "/www/log/bin/rsync.4.3gpp.res.img.sh ".$_COOKIE["_uname"]." ".$rsyncpath.$filename;
exec($cmd);
return $imgNames;
}else{
return null;
}
}else{
return null;
}
}
图片上传程序
function zd_word_uploadImage($FILES,$type){
global $resrootpath;
$img_name = $FILES['name'];
$tmp_name = $FILES['tmp_name'];
$imgExtArr = array('.gif','.jpg','.JPEG');//图片格式
$imgExt = strrchr($img_name,".");//获得后缀
if (in_array($imgExt,$imgExtArr)){
//取时间
$sec = explode(" ", microtime());
$micro = explode(".", $sec[0]);
$times = $sec[1].substr($micro[1], 0, 3);
$subTime = substr($times,-4,2)."/".substr($times,-2)."/"; //截取时间路径
$imgNames = $times.$imgExt;//图片名字
$picpath = "images/wiki/".$subTime.$imgNames;//资源路径
$muf = move_uploaded_file($tmp_name,$resrootpath.$picpath);
if($muf){//上传源图片
//同步原图
$cmd01 = "/www/log/bin/rsync.4.3gpp.res.img.sh ".$_COOKIE["_uname"]." ".$picpath;
exec($cmd01);
//=======缩图
if($type == 1){//长
$width = 80; $height = 60;
}elseif($type == 2){//竖
$width = 60; $height = 80;
}else{//方版
$width = 80; $height = 80;
}
$newImgName = $times."_".$width."_".$height.$imgExt;; //缩图图片名称
$smallpicpath = "images/wiki/".$subTime.$newImgName; //缩图的路径
$cmd02 = "convert ".$resrootpath.$picpath." -coalesce ".$resrootpath.$smallpicpath;//开始缩图
exec($cmd02);
$cmd03 = "convert -resize ".$width."x".$height."! ".$resrootpath.$smallpicpath." ".$resrootpath.$smallpicpath;
exec($cmd03);
//同步缩图图片
$cmd04 = "/www/log/bin/rsync.4.3gpp.res.img.sh ".$_COOKIE["_uname"]." ".$smallpicpath;
exec($cmd04);
return $newImgName;
}else{
return null;
}
}else{
return null;
}
}