现提供生成新闻头条中图片标题的部分源代码,请高手整合!!
首先声明,版权不归我所有,只是个借鉴
<?php /*******************************************\ * 版权所有 杜京 2007.06.28 中国新闻社(北京) * * 网名:官不聊生 QQ:30300969 请勿用于商业! * \*******************************************/ $text = $_GET['title']; $border = $_GET['border']; $font = $_GET['fonts']; if(empty($_GET['url'])){ $url = 'http://www.gxhangpai.cn'; }else{ $url = $_GET['url']; } $type = $_GET['type']; $fontsize = '25'; $text = iconv("GB2312","UTF-8",$text); $imagedir = date('Y-m-d'); if(!file_exists($imagedir)){ mkdir($imagedir,0777); //chmod($imagedir,0777); //return true; } $imagename = explode(" ",$_GET['pubdate']); $imagename0 = $imagename['0']; $imagename0 = explode("-",$imagename0); $imagename1 = $imagename['1']; $imagename1 = explode(":",$imagename1); $imagename = $imagename0[0].$imagename0[1].$imagename0[2].$imagename1[0].$imagename1[1].$imagename1[2];
$box = imagettfbbox ($fontsize, 0, $font, $text); $textW = $box[2] - $box[0]; $textH= $box[3]-$box[5]; $paddingx = 15; $paddingy = 15; $width = $textW+$paddingx; $height= $textH+$paddingy;
$textx = $paddingx/2; $texty = $height - $paddingy;
$shadoffx = 1; $shadoffy = 1;
$img = imagecreatetruecolor($width,$height); $white = imagecolorallocate($img,255,255,255); $black = imagecolorallocate($img,0,0,0); $lightgrey = imagecolorallocate($img,200,200,200); $grey = imagecolorallocate($img,200,200,200); $bgcol = imagecolorallocate($img,227,235,255); $rgb = $_GET['rgb']; $rgb = explode(",",$rgb); $fgcol = imagecolorallocate($img,$rgb['0'],$rgb['1'],$rgb['2']); imagefill($img,0,0,$bgcol);
imagettftext($img, $fontsize, 0, $textx+$shadoffx, $texty+$shadoffy, $grey, $font, $text);
imagettftext($img, $fontsize, 0, $textx, $texty, $fgcol, $font, $text);
if ($border == "flat") { imageline ($img,0,0,$width,0,$white);imageline ($img,0,0,0,$height,$white); imageline ($img,1,1,$width,1,$grey);imageline ($img,1,1,1,$height-1,$grey); imageline ($img,0,$height-1,$width-1,$height-1,$white);imageline ($img,$width-1,$height-1,$width-1,0,$white); imageline ($img,2,$height-2,$width-2,$height-2,$grey);imageline ($img,$width-2,$height-2,$width-2,2,$grey); } if ($border == "out") { imageline ($img,0,0,$width,0,$white);imageline ($img,0,0,0,$height,$white); imageline ($img,1,1,$width,1,$lightgrey);imageline ($img,1,1,1,$height-1,$lightgrey); imageline ($img,0,$height-1,$width-1,$height-1,$black);imageline ($img,$width-1,$height-1,$width-1,0,$black); imageline ($img,2,$height-2,$width-2,$height-2,$grey);imageline ($img,$width-2,$height-2,$width-2,2,$grey);
} if ($border == "in") { imageline ($img,0,0,$width,0,$black);imageline ($img,0,0,0,$height,$black); imageline ($img,1,1,$width,1,$grey);imageline ($img,1,1,1,$height-1,$grey); imageline ($img,0,$height-1,$width-1,$height-1,$white);imageline ($img,$width-1,$height-1,$width-1,0,$white); imageline ($img,2,$height-2,$width-2,$height-2,$lightgrey);imageline ($img,$width-2,$height-2,$width-2,2,$lightgrey); }
//Header ("Content-type: image/png"); //imagepng($img);
imagepng($img,$imagedir.'/'.$imagename.'.png'); imagedestroy($img); ob_start(); $text = iconv("UTF-8","GB2312",$text); $content ="<a href='".$url."' target='_blank'><img src='/dede/".$imagedir."/".$imagename.".png' border='0' alt='".$text."'></a>"; echo $content; $page = ob_get_contents(); ob_end_clean(); $cwd = getcwd(); $file = "$cwd" .'/'. $type."_topnews.inc"; @chmod($file,0777); $fw = fopen($file, "w"); fputs($fw,$page, strlen($page)); fclose($fw); echo "<script>javascript:window.location.href='maketopnews_homepage.php?type=".$type."'</script>"; die(); ?>
以下是预览代码
<?php /*******************************************\ * 版权所有 杜京 2007.06.28 中国新闻社(北京) * * 网名:官不聊生 QQ:30300969 请勿用于商业! * \*******************************************/ $text = $_GET['title']; $border = $_GET['border']; $font = $_GET['fonts']; $fontsize = '25'; $text = iconv("GB2312","UTF-8",$text);
$box = imagettfbbox ($fontsize, 0, $font, $text); $textW = $box[2] - $box[0]; $textH= $box[3]-$box[5]; $paddingx = 15; $paddingy = 15; $width = $textW+$paddingx; $height= $textH+$paddingy;
$textx = $paddingx/2; $texty = $height - $paddingy;
$shadoffx = 1; $shadoffy = 1;
$img = imagecreatetruecolor($width,$height); $white = imagecolorallocate($img,255,255,255); $black = imagecolorallocate($img,0,0,0); $lightgrey = imagecolorallocate($img,200,200,200); $grey = imagecolorallocate($img,200,200,200); $bgcol = imagecolorallocate($img,227,235,255); $rgb = $_GET['rgb']; $rgb = explode(",",$rgb); $fgcol = imagecolorallocate($img,$rgb['0'],$rgb['1'],$rgb['2']); imagefill($img,0,0,$bgcol);
imagettftext($img, $fontsize, 0, $textx+$shadoffx, $texty+$shadoffy, $grey, $font, $text);
imagettftext($img, $fontsize, 0, $textx, $texty, $fgcol, $font, $text);
if ($border == "flat") { imageline ($img,0,0,$width,0,$white);imageline ($img,0,0,0,$height,$white); imageline ($img,1,1,$width,1,$grey);imageline ($img,1,1,1,$height-1,$grey); imageline ($img,0,$height-1,$width-1,$height-1,$white);imageline ($img,$width-1,$height-1,$width-1,0,$white); imageline ($img,2,$height-2,$width-2,$height-2,$grey);imageline ($img,$width-2,$height-2,$width-2,2,$grey); } if ($border == "out") { imageline ($img,0,0,$width,0,$white);imageline ($img,0,0,0,$height,$white); imageline ($img,1,1,$width,1,$lightgrey);imageline ($img,1,1,1,$height-1,$lightgrey); imageline ($img,0,$height-1,$width-1,$height-1,$black);imageline ($img,$width-1,$height-1,$width-1,0,$black); imageline ($img,2,$height-2,$width-2,$height-2,$grey);imageline ($img,$width-2,$height-2,$width-2,2,$grey);
} if ($border == "in") { imageline ($img,0,0,$width,0,$black);imageline ($img,0,0,0,$height,$black); imageline ($img,1,1,$width,1,$grey);imageline ($img,1,1,1,$height-1,$grey); imageline ($img,0,$height-1,$width-1,$height-1,$white);imageline ($img,$width-1,$height-1,$width-1,0,$white); imageline ($img,2,$height-2,$width-2,$height-2,$lightgrey);imageline ($img,$width-2,$height-2,$width-2,2,$lightgrey); }
header("Content-type: image/png"); imagepng($img); imagedestroy($img); ?>
由于水平有限不知道该如何整合,请高手赐教
|
|
|