PHP imagestring 图像GD库函数

  • 定义和用法

    imagestring - 水平地画一行字符串
  • 版本支持

    PHP4 PHP5 PHP7
    支持 支持 支持
  • 语法

    imagestring ( resource $image , int $font , int $x , int $y , string $s , int $col )
    
    imagestring() 用 col 颜色将字符串 s 画到 image 所代表的图像的 x,y 坐标处(这是字符串左上角坐标,整幅图像的左上角为 0,0)。如果 font 是 1,2,3,4 或 5,则使用内置字体。
  • 参数

    参数 必需的 描述
    image 由图象创建函数(例如 imagecreatetruecolor() )返回的图象资源。
    font 字体
    x 开始的x坐标
    y 开始的y坐标
    s 写入的字符串
    col 颜色
  • 返回值

    成功时返回 TRUE, 或者在失败时返回 FALSE。
  • 示例

    // 建立一幅 100X30 的图像
    $im = imagecreate(200, 60);
    
    // 白色背景和蓝色文本
    $bg = imagecolorallocate($im, 255, 255, 255);
    $textcolor = imagecolorallocate($im, 0, 0, 255);
    
    // 把字符串写在图像左上角
    imagestring($im, 5, 0, 0, "Hello world!", $textcolor);
    
    // 输出图像
    header("Content-type: image/png");
    imagepng($im);
    
    以上示例输出:
    gd_43      
    
  • 相关函数

    imageloadfont() - 载入一新字体
    imagettftext() - 用 TrueType 字体向图像写入文本