php中有关GD库的使用

本文介绍了PHP中使用GD库进行动态图片生成的方法,并提供了如何查看图片像素点坐标的技巧,通过画图工具可以查看图片任意位置的像素值。
摘要由CSDN通过智能技术生成
class Test extends IndexBase
{
   
	protected $text = 'php网站程序开发';
	//protected $font = {$_SERVER['DOCUMENT_ROOT']}.'/public/mui/fonts/mui.ttf'; //如果没有要自己加载到相应的目录下(本地www)
	protected $angle = 0;
	protected $size = 15;
	protected $showX = 100;
	protected $showY = 160;
	
	protected $text0 = '2011 年 12 月 12 日';
	protected $angle0 = 0;
	protected $showX0 = 230;
	protected $showY0 = 200;
	
	protected $text1 = '新郎';
	protected $angle1 = 20;
	protected $showX1 = 135;
	protected $showY1 = 285;
	
	protected $text2 = '新娘';
	protected $angle2 = 20;
	protected $showX2 = 300;
	protected $showY2 = 285;
	
	protected $text3 = '北京市海淀区香格里拉酒店';
	protected $angle3 = 0;
	protected $showX3 = 120;
	protected $showY3 = 445;
	
	protected $text4 = '上午十一点整';
	protected $angle4 = 0;
	protected $showX4 = 305;
	protected $showY4 = 480;

    /**给图片添加文字水印
     * @return mixed
     */
    public function index()
    {
   
        //打开图片
        //1配置图片路径(你想要操作的图片路径)
        $src = $_SERVER['DOCUMENT_ROOT'].'/public/static/images/wutu.jpg';
        //2获取图片信息(通过GD库提供的方法,得到你想要处理的图片基础信息)
        $info = getimagesize($src);
       /* echo "<pre>";
        print_r($info);*/

        //3通过图像编号获取图像类型 不加false 为.jpg 加false为jpg
        $type= image_type_to_extension($info[2],false);
        //4在内存中创建一个和我们图像类型一样的图像
        $fun ="imagecreatefrom{
     $type}";
        //5把图片复制到内存
        $image = $fun($src);
        //操作图片
        //1设置字体路径
        $font = $_SERVER['DOCUMENT_ROOT'].'/public/static/fonts/simsun.ttf';
        //2填写水印内容
        $content = '航航';
        $content = mb_convert_encoding($content, "html-entities", "utf-8");
        //3设置字体的颜色和透明度 图片 颜色 透明度
        $col = imagecolorallo
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值