企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 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编码后传输 ~~~