你有没有去除BMO头,有时会因bmo的原因而产生不了图片,你可以试一下下面这个代码
<?php$gd_support = extension_loaded('gd')
if ($gd_support) $gd_info = gd_info() else $gd_info = array()
$im = imagecreatetruecolor(175,60)
$bule = imagecolorallocate($im,100,255,255)
$imgcolor = imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255))
imagefill($im,0,0,$blue)
for($i=0$i<4$i++){
imageline($im,rand(0,20),0,100,rand(0,60),$imgcolor)
}
for($i=0$i<100$i++){
imagesetpixel($im,rand(0,50),rand(0,30),$imgcolor)
}
$str=substr(str_shuffle('ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'),0,4)
imagestring($im,4,10,10,$str,$imgcolor)
ob_clean()
header('content-type: image/png')
imagepng($im)
imagedestroy($im)
?>
新建一个文件名为img.php。引用方法如下:
http://dome.com/img.php?=微信图片地址
代码如下。
<?phpheader("Content-Type:image/png")
$string = $_SERVER["QUERY_STRING"]
/*换一张空白图片,如果遇到错误,需要用上*/
$im = imagecreate(600, 300)
$black = imagecolorallocate($im, 100, 100, 100)//图片背景
$white = imagecolorallocate($im, 255, 255, 255)
/*获取图片的真实地址*/
$url = strstr($string, "http")
if (!$url) {
imagettftext($im, 18, 0, 200, 100, $white, "./fonts/hwxh.ttf", "Error 001")
imagettftext($im, 14, 0, 150, 150, $white, "./fonts/hwxh.ttf", "请在参数中输入图片的绝对地址。")
imagepng($im)
exit()
}
@$imgString = urlOpen($url)
if ($imgString == "") {
imagettftext($im, 18, 0, 200, 100, $white, "./fonts/hwxh.ttf", "Error 002")
imagettftext($im, 14, 0, 70, 150, $white, "./fonts/hwxh.ttf", "加载远程图片失败,请确认图片的地址能正常访问。")
imagepng($im)
exit()
}
/*如果没有错误*/
$im = imagecreatefromstring($imgString)
$white = imagecolorallocate($im, 255, 255, 255)
/*加上水印*/
//imagettftext($im, 12, 0, 20, 20, $white, "./fonts/hwxh.ttf", "水印的文字1")
//imagettftext($im, 12, 0, 5, 35, $white, "./fonts/hwxh.ttf", "水印(可以写你的网址)")
imagepng($im)
/*抓取图片*/
function urlOpen($url, $data = null, $ua = '')
{
if ($ua == '') {
$ua = 'MQQBrowser/26 Mozilla/5.0 (Linux U Android 2.3.7 zh-cn MB200 Build/GRJ22 CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
} else {
$ua = $ua
}
$ch = curl_init()
curl_setopt($ch, CURLOPT_URL, $url)
curl_setopt($ch, CURLOPT_USERAGENT, $ua)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1)
$content = curl_exec($ch)
curl_close($ch)
return $content
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)