# gd库函数
>gd模块支持的图片压缩格式有:YCbCr,RGBA,NRGBA,Paletted
> 函数太多了,懒得写文档了,看例子先:[例子](例子.md)
**gd库常量:**
~~~
// drawImageEx / draw_mode 绘制模式
{"DRAW_OVER", "DRAW_SRC"},
// drawImageEx / resize_mode:缩放模式
{"RESIZE_NEAREST_NEIGHBOR", "RESIZE_BILINEAR", "RESIZE_BICUBIC", "RESIZE_MITCHELL_NETRAVALI", "RESIZE_LANCZOS2", "RESIZE_LANCZOS3"},
// newSurfacePattern 表面样式图案
{"SURFACE_REPEAT_BOTH", "SURFACE_REPEAT_X", "SURFACE_REPEAT_Y", "SURFACE_REPEAT_NONE"},
// 填充模式 setFillRule
{"FILL_RULE_WINDING", "FILL_RULE_EVEN_ODD"},
// 线加入模式 setLineJoin
{"LINE_JOIN_ROUND", "LINE_JOIN_BEVEL"},
// 线两端样式 setLineCap
{"LINE_CAP_ROUND", "LINE_CAP_BUTT", "LINE_CAP_SQUARE"},
// 绘制字符串对齐方式 drawStringWrapped
{"ALIGN_LEFT", "ALIGN_CENTER", "ALIGN_RIGHT"},
~~~
## 绘制函数
~~~lua|woo
drawImageEx(x,y,width,height,resize_mode,draw_mode)
drawPoint(x, y, r number)
drawLine(x1, y1, x2, y2 number)
drawRectangle(x, y, w, h number)
drawRoundedRectangle(x, y, w, h, r number)
drawCircle(x, y, r number)
drawArc(x, y, r, angle1, angle2 number)
drawEllipse(x, y, rx, ry number)
drawEllipticalArc(x, y, rx, ry, angle1, angle2 number)
drawRegularPolygon(n int, x, y, r, rotation number)
drawImage(gd, x, y int)
drawImageAnchored(im image.Image, x, y int, ax, ay number)
setPixel(x, y int)
moveTo(x, y number)
lineTo(x, y number)
quadraticTo(x1, y1, x2, y2 number)
cubicTo(x1, y1, x2, y2, x3, y3 number)
closePath()
clearPath()
newSubPath()
clear()
stroke()
fill()
strokePreserve()
fillPreserve()
~~~
> 通常需要将图像居中于某一点。将“ax”和“ay”设置为0.5时使用“drawinimagearchored”。使用0左对齐或上对齐。使用1右对齐或下对齐。`DrawStringAnchored`对文本也有同样的作用,因此您不需要自己调用'MeasureString'。
## 文字函数
~~~lua|woo
drawString(s string, x, y number)
drawStringAnchored(s string, x, y, ax, ay number)
drawStringWrapped(s string, x, y, ax, ay, width, lineSpacing number, align Align)
measureString(s string) (w, h number)
measureMultilineString(s string, lineSpacing number) (w, h number)
wordWrap(s string, w number) []string
setFontFace(fontFace font.Face)
loadFontFace(path string, points number) error
~~~
## 颜色函数
> 为了您的方便,可以用几种不同的方式设置颜色。
~~~lua|woo
setRGB(r, g, b number)
setRGBA(r, g, b, a number)
setRGB255(r, g, b number)
setRGBA255(r, g, b, a number)
setHexColor(x string)
~~~
## 笔划和填充选项
~~~lua|woo
setLineWidth(lineWidth number)
setLineCap(lineCap LineCap)
setLineJoin(lineJoin LineJoin)
setDash(dashes ...number)
setDashOffset(offset number)
setFillRule(fillRule FillRule)
~~~
## 渐变和图案
> 线性和径向渐变和表面图案。您还可以实现自己的模式。
~~~lua|woo
setFillStyle(pattern Pattern)
setStrokeStyle(pattern Pattern)
newSolidPattern(color color.Color)
newLinearGradient(x0, y0, x1, y1 number)
newRadialGradient(x0, y0, r0, x1, y1, r1 number)
newSurfacePattern(im image.Image, op RepeatOp)
~~~
## 转换函数
~~~lua|woo
identity()
resize(width uint, height uint, img image.Image, mode)
mode:
translate(x, y number)
scale(x, y number)
rotate(angle number)
shear(x, y number)
scaleAbout(sx, sy, x, y number)
rotateAbout(angle, x, y number)
shearAbout(sx, sy, x, y number)
transformPoint(x, y number) (tx, ty number)
invertY()
setBorderRadius(gd,r) -- r为圆角大小:px,为0时图片转变为圆形头像
~~~
> 通常需要围绕不是原点的点旋转或缩放。函数“RotateAbout”、“ScaleAbout”、“ShearAbout”是为方便起见而提供的。
`如果Y从下到上增加而不是默认的从上到下增加,则提供InvertY。
## 堆栈函数
> 保存并还原上下文的状态。这些可以嵌套。
~~~lua|woo
push()
pop()
~~~
## 剪切函数
> 使用剪裁区域可以将绘图操作限制为使用路径定义的区域。
~~~lua|woo
clip()
clipPreserve()
resetClip()
asMask() *image.Alpha
setMask(mask *image.Alpha)
invertMask()
~~~
## 帮助函数
~~~lua|woo
radians(degrees number) number
degrees(radians number) number
loadImage(path string) error 载入一个图片
savePng(path string) error 保存为png格式
saveJpg(path string,quality) error 保存为jpg格式
getSize() 返回图片width,height
bytes() 获取画板上的字节集数据,可以使用base64编码后传输
~~~
- 序言
- 安装
- 可视化编辑器
- woo 命令行参数详解
- 测试用例
- 简单http服务
- 正则
- gpio控制硬件设备
- 比武不招亲
- 和php比WebServer
- woo语法
- 语法简介
- 基本语法
- woo数据类型
- woo变量
- woo循环
- woo流程控制
- woo函数
- woo运算符
- woo字符串
- 类
- 类的继承
- 模块
- 数组
- 迭代
- table
- 元表(魔术方法)
- 错误处理
- 面向对象
- woo开发必须注意事项
- 函数/模块
- 内置函数
- webServer专属函数
- 内置模块
- gd-2d绘图库
- 2D图形例子
- websockets用例
- buffer缓存
- http
- orm数据库连接
- redis-ssdb连接
- queue队列
- 其他特别函数
- sockets
- 启动线程如何
- Murphy-http Web框架
- 简介
- 全局函数
- model
- view
- controller
- 消息队列
- 全局线程锁
- 包管理器/coder wooyri package manager
- 最ok的包上榜名单
- woo栗子
- 函数传参
- 编码解码
- http模块用例
- 移动读写文件流用例
- 文件下载用例
- 数组迭代
- 进制转换
- _choose用例
- 日期时间用例
- 注明
- wop 码包|coder wooyri peogram
- 码人激励计划