最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php入门教程七(图片操作与实例)
时间:2010-11-04 编辑:简简单单 来源:一聚教程网
本文章利用用大量的例子来讲解php教程代码对图片操作的讲解。下面来看看一个个实例教程吧.
$;
$;
//创建背景图
$im = imagecreatetruecolor($width, $height);
//分配颜色
$white = imagecolorallocate ($im, 255, 255, 255);
$blue = imagecolorallocate ($im, 0, 0, 64);
//绘制颜色至图像中
imagefill($im, 0, 0, $blue);
//绘制字符串:hello,php
imagestring($im, 10, 100, 120, 'hello,php', $white);
//输出图像,定义头
header ('content-type: image/png');
//将图像发送至浏览器
imagepng($im);
//清除资源
imagedestroy($im);
?>
实例二生成缩略图片
header("content-type: image/jpeg");
// 载入图像
$imagen1 = imagecreatefromjpeg("imagen1.jpg");
$imagen2 = imagecreatefromjpeg("imagen2.jpg");// 复制图像
imagecopy($imagen1,$imagen2,0,0,0,0,200,150);// 输出jpeg图像
imagejpeg($imagen1);//释放内存
imagedestroy($imagen2);
imagedestroy($imagen1);?>
获取图片大小信息
$info = getimagesize("imagen2.jpg");
print_r($info);?>
绘制png图片
//png格式图像处理函数
function loadpng ($imgname) {
$im = @imagecreatefrompng ($imgname);
if (!$im) { //载入图像失败
$im = imagecreate (400, 30);
$bgc = imagecolorallocate ($im, 255, 255, 255);
$tc = imagecolorallocate ($im, 0, 0, 0);
imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
imagestring($im, 4, 5, 5, "error loading: $imgname", $tc);
}
return $im;
}
$imgpng=loadpng("./karte.png");
/* 输出图像到浏览器 */
header("content-type: image/png");
imagepng($imgpng);
?>
给图片加文字
//创建 100*30 图像
$im = imagecreate(100, 30);
// white background and blue text
$bg = imagecolorallocate($im, 200, 200, 200);
$textcolor = imagecolorallocate($im, 0, 0, 255);
// write the string at the top left
imagestring($im, 5, 0, 0, "hello world!", $textcolor);
// output the image
header ("content-type: image/jpeg");
imagejpeg ($im);
imagedestroy($im);?>
-
上一个: php 自定义UTF8和cp1251函数
相关文章
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24
- php数组查询元素位置方法介绍 10-24