您的位置:首页 > 编程语言 > PHP开发

php thinkphp imagepng无法显示图片

2015-01-16 13:27 976 查看
php代码浏览器可正常显示图片,thinkPhp控制器不可行在header前加上
ob_clean ();


即可

thinkphp 控制器代码

/**
* 显示图标
*/
public function icon() {
//清除输出,去掉前面的html
ob_clean ();
header ( "Content-type: image/png" );
// 文件名
$type = $_GET ["type"];
if (empty ( $_GET ["color"] )) {
$fileName = $type . '.png';
} else {
$color = $_GET ["color"];
$fileName = $type . '_' . $color . '.png';
}
// 旋转角度
$angle = $_GET ["angle"];
if ($angle > 180) {
$angle = 360 - $angle;
} else {
$angle = - $angle;
}
// 文件绝对路径
$fileName2 = IconPath . $fileName;
// 实例图片
$im = imagecreatefrompng ( $fileName2 );
$alpha = imagecolorallocatealpha ( $im, 0, 0, 0, 127 );
$re = imagerotate ( $im, $angle, $alpha );
// 保留透明度
imagesavealpha ( $re, true );
// 输出到浏览器
imagepng ( $re );
imagedestroy ( $im );
imagedestroy ( $re );
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: