function createthumb1($img,$thumb_width,$thumb_height,$ctype="1") { if($img=="") { echo DAYU_PATH."images/nophoto.gif"; } else { $info=imageinfo(DAYU_ROOT.$img); switch ($info['mime']) { case "image/gif": $infotype="gif"; break; case "image/jpeg": $infotype="jpeg"; break; case "image/png": $infotype="png"; break; case "image/bmp": $infotype="bmp"; break; } $thumbname='thumb_'.$info['name'].'_'.$thumb_width.'x'.$thumb_height.'.'.$infotype; if(!file_exists($info['path'].$thumbname)) { $thumb_w=intval($thumb_width)?intval($thumb_width):400; $thumb_h=intval($thumb_width)?intval($thumb_width):300; if($ctype==1) // 按照比例生成缩略图 { $scale=min(1,min($thumb_width/$info['width'],$thumb_height/$info['height'])); //按比例缩放 $thumb_width=intval($info['width']*$scale); $thumb_height=intval($info['height']*$scale); } else // 按照固定宽高生成缩略图 { $thumb_width=intval($thumb_width); $thumb_height=intval($thumb_height); } $createfunc='imagecreatefrom'.($infotype=='jpg'?'jpeg':$infotype); $im=$createfunc(DAYU_ROOT.$img); if($infotype=='png'){ imagesavealpha($im,true); } $thumb_im=$infotype!='gif' && function_exists('imagecreatetruecolor')?imagecreatetruecolor($thumb_width,$thumb_height):imagecreate($thumb_width,$thumb_height); if($infotype=='png') { imagealphablending($thumb_im,false); imagesavealpha($thumb_im,true); } imagecopyresampled($thumb_im,$im,0,0,0,0,$thumb_width,$thumb_height,$info['width'],$info['height']); $imagefunc='image'.($infotype=='jpg'?'jpeg':$infotype); $imagefunc($thumb_im,$info['path'].$thumbname); imagedestroy($im); imagedestroy($thumb_im); } echo str_replace(DAYU_ROOT,"",$info['path']).$thumbname; } } function DateDiff($interval, $date1, $date2) { // @See: It gets the number of the seconds in the one of the 2nd period day interval. $time_difference = $date2 - $date1; switch ($interval) { case "w": $retval = bcdiv($time_difference, 604800); break; case "d": $retval = bcdiv($time_difference, 86400); break; case "h": $retval = bcdiv($time_difference, 3600); break; case "n": $retval = bcdiv($time_difference, 60); break; case "s": $retval = $time_difference; break; } return $retval; } function geturlfile($url) { $url=trim($url); $content=''; if(extension_loaded('curl')) { $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch,CURLOPT_HEADER,0); $content=curl_exec($ch); curl_close($ch); } else { $content=file_get_contents($url); } return trim($content); } function cwrite($cachename,$string,$path='') { $path=empty($path)?CACHE_PATH:$path; $cachefile=$path.$cachename; @file_put_contents($cachefile,$string); @chmod($cachefile,0777); return DAYU_PATH."data/cache/".$cachename; } function jsonapi($url) { $string=geturlfile($url); if($string) { $array=json_decode($string,true); } return $array; } function getkeywords($keywords) { $keywords=str_replace(',','|',str_replace(',','|',str_replace(' ','|',trim($keywords)))); $arraykey=explode('|',$keywords); return $arraykey; } ?>