PHP 图像处理

PHP 教程 · 2019-01-21 21:59:35

PHP 提供了丰富的图像处理函数,主要包括:

函数描述
gd_info() 取得当前安装的 GD 库的信息
getimagesize() 获取图像信息
getimagesizefromstring() 获取图像信息
image_type_to_extension() 获取图片后缀
image_type_to_mime_type() 返回图像的 MIME 类型
image2wbmp() 输出WBMP图片
imageaffine() 返回经过仿射变换后的图像
imageaffinematrixconcat() 连接两个矩阵
imageaffinematrixget() 获取矩阵
imagealphablending() 设定图像的混色模式
imageantialias() 是否使用抗锯齿(antialias)功能
imagearc() 画椭圆弧
imagechar() 写出横向字符
imagecharup() 垂直地画一个字符
imagecolorallocate() 为一幅图像分配颜色
imagecolorallocatealpha() 为一幅图像分配颜色和透明度
imagecolorat() 取得某像素的颜色索引值
imagecolorclosest() 取得与指定的颜色最接近的颜色的索引值
imagecolorclosestalpha() 取得与指定的颜色加透明度最接近的颜色的索引
imagecolorclosesthwb() 取得与指定的颜色最接近的色度的黑白色的索引
imagesx() 、imagesy() 获取图像宽度与高度

GD 库

使用 PHP 图像处理函数,需要加载 GD 支持库。请确定 php.ini 加载了 GD 库:

Window 服务器上:

extension = php_gd2.dll

Linux 和 Mac 系统上:

extension = php_gd2.so

使用 gd_info() 函数可以查看当前安装的 GD 库的信息:

<?php
var_dump(gd_info());
?>

输出大致如下:

array(12) {
  ["GD Version"]=>
  string(26) "bundled (2.1.0 compatible)"
  ["FreeType Support"]=>
  bool(true)
  ["FreeType Linkage"]=>
  string(13) "with freetype"
  ["T1Lib Support"]=>
  bool(false)
  ["GIF Read Support"]=>
  bool(true)
  ["GIF Create Support"]=>
  bool(true)
  ["JPEG Support"]=>
  bool(true)
  ["PNG Support"]=>
  bool(true)
  ["WBMP Support"]=>
  bool(true)
  ["XPM Support"]=>
  bool(false)
  ["XBM Support"]=>
  bool(true)
  ["JIS-mapped Japanese Font Support"]=>
  bool(false)
}

点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

高效能程序员的修炼

高效能程序员的修炼

[美]Jeff Atwood / 陆其明、张健 / 人民邮电出版社 / 2013-7 / 49

jeff atwood于2004年创办coding horror博客(http://www.codinghorror.com),记录其在软件开发经历中的所思所想、点点滴滴。时至今日,该博客每天都有近10万人次的访问量,读者纷纷参与评论,各种观点与智慧在那里不断激情碰撞。 《高效能程序员的修炼》是coding horror博客中精华文章的集合。全书分为12章,涉及迈入职业门槛、高效能编程、应聘......一起来看看 《高效能程序员的修炼》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码