{"id":13413183,"url":"https://github.com/fogleman/gg","last_synced_at":"2025-05-13T16:12:07.755Z","repository":{"id":37444732,"uuid":"52038678","full_name":"fogleman/gg","owner":"fogleman","description":"Go Graphics - 2D rendering in Go with a simple API.","archived":false,"fork":false,"pushed_at":"2023-12-14T12:59:35.000Z","size":1251,"stargazers_count":4550,"open_issues_count":94,"forks_count":368,"subscribers_count":94,"default_branch":"master","last_synced_at":"2025-04-23T20:59:48.926Z","etag":null,"topics":["2d","2d-graphics","go","graphics","rendering"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/fogleman/gg","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fogleman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-18T21:05:08.000Z","updated_at":"2025-04-22T07:05:54.000Z","dependencies_parsed_at":"2023-01-21T10:17:55.029Z","dependency_job_id":"142db874-4512-42b1-b152-0453d8a24c0a","html_url":"https://github.com/fogleman/gg","commit_stats":{"total_commits":151,"total_committers":17,"mean_commits":8.882352941176471,"dds":"0.16556291390728473","last_synced_commit":"8febc0f526adecda6f8ae80f3869b7cd77e52984"},"previous_names":["fogleman/dd"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fogleman%2Fgg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fogleman%2Fgg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fogleman%2Fgg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fogleman%2Fgg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fogleman","download_url":"https://codeload.github.com/fogleman/gg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250514767,"owners_count":21443208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2d","2d-graphics","go","graphics","rendering"],"created_at":"2024-07-30T20:01:34.622Z","updated_at":"2025-04-23T20:59:57.367Z","avatar_url":"https://github.com/fogleman.png","language":"Go","readme":"# Go Graphics\n\n`gg` is a library for rendering 2D graphics in pure Go.\n\n![Stars](http://i.imgur.com/CylQIJt.png)\n\n## Installation\n\n    go get -u github.com/fogleman/gg\n\nAlternatively, you may use gopkg.in to grab a specific major-version:\n\n    go get -u gopkg.in/fogleman/gg.v1\n\n## Documentation\n\n- godoc: https://godoc.org/github.com/fogleman/gg\n- pkg.go.dev: https://pkg.go.dev/github.com/fogleman/gg?tab=doc\n\n## Hello, Circle!\n\nLook how easy!\n\n```go\npackage main\n\nimport \"github.com/fogleman/gg\"\n\nfunc main() {\n    dc := gg.NewContext(1000, 1000)\n    dc.DrawCircle(500, 500, 400)\n    dc.SetRGB(0, 0, 0)\n    dc.Fill()\n    dc.SavePNG(\"out.png\")\n}\n```\n\n## Examples\n\nThere are [lots of examples](https://github.com/fogleman/gg/tree/master/examples) included. They're mostly for testing the code, but they're good for learning, too.\n\n![Examples](http://i.imgur.com/tMFoyzu.png)\n\n## Creating Contexts\n\nThere are a few ways of creating a context.\n\n```go\nNewContext(width, height int) *Context\nNewContextForImage(im image.Image) *Context\nNewContextForRGBA(im *image.RGBA) *Context\n```\n\n## Drawing Functions\n\nEver used a graphics library that didn't have functions for drawing rectangles\nor circles? What a pain!\n\n```go\nDrawPoint(x, y, r float64)\nDrawLine(x1, y1, x2, y2 float64)\nDrawRectangle(x, y, w, h float64)\nDrawRoundedRectangle(x, y, w, h, r float64)\nDrawCircle(x, y, r float64)\nDrawArc(x, y, r, angle1, angle2 float64)\nDrawEllipse(x, y, rx, ry float64)\nDrawEllipticalArc(x, y, rx, ry, angle1, angle2 float64)\nDrawRegularPolygon(n int, x, y, r, rotation float64)\nDrawImage(im image.Image, x, y int)\nDrawImageAnchored(im image.Image, x, y int, ax, ay float64)\nSetPixel(x, y int)\n\nMoveTo(x, y float64)\nLineTo(x, y float64)\nQuadraticTo(x1, y1, x2, y2 float64)\nCubicTo(x1, y1, x2, y2, x3, y3 float64)\nClosePath()\nClearPath()\nNewSubPath()\n\nClear()\nStroke()\nFill()\nStrokePreserve()\nFillPreserve()\n```\n\nIt is often desired to center an image at a point. Use `DrawImageAnchored` with `ax` and `ay` set to 0.5 to do this. Use 0 to left or top align. Use 1 to right or bottom align. `DrawStringAnchored` does the same for text, so you don't need to call `MeasureString` yourself.\n\n## Text Functions\n\nIt will even do word wrap for you!\n\n```go\nDrawString(s string, x, y float64)\nDrawStringAnchored(s string, x, y, ax, ay float64)\nDrawStringWrapped(s string, x, y, ax, ay, width, lineSpacing float64, align Align)\nMeasureString(s string) (w, h float64)\nMeasureMultilineString(s string, lineSpacing float64) (w, h float64)\nWordWrap(s string, w float64) []string\nSetFontFace(fontFace font.Face)\nLoadFontFace(path string, points float64) error\n```\n\n## Color Functions\n\nColors can be set in several different ways for your convenience.\n\n```go\nSetRGB(r, g, b float64)\nSetRGBA(r, g, b, a float64)\nSetRGB255(r, g, b int)\nSetRGBA255(r, g, b, a int)\nSetColor(c color.Color)\nSetHexColor(x string)\n```\n\n## Stroke \u0026 Fill Options\n\n```go\nSetLineWidth(lineWidth float64)\nSetLineCap(lineCap LineCap)\nSetLineJoin(lineJoin LineJoin)\nSetDash(dashes ...float64)\nSetDashOffset(offset float64)\nSetFillRule(fillRule FillRule)\n```\n\n## Gradients \u0026 Patterns\n\n`gg` supports linear, radial and conic gradients and surface patterns. You can also implement your own patterns.\n\n```go\nSetFillStyle(pattern Pattern)\nSetStrokeStyle(pattern Pattern)\nNewSolidPattern(color color.Color)\nNewLinearGradient(x0, y0, x1, y1 float64)\nNewRadialGradient(x0, y0, r0, x1, y1, r1 float64)\nNewConicGradient(cx, cy, deg float64)\nNewSurfacePattern(im image.Image, op RepeatOp)\n```\n\n## Transformation Functions\n\n```go\nIdentity()\nTranslate(x, y float64)\nScale(x, y float64)\nRotate(angle float64)\nShear(x, y float64)\nScaleAbout(sx, sy, x, y float64)\nRotateAbout(angle, x, y float64)\nShearAbout(sx, sy, x, y float64)\nTransformPoint(x, y float64) (tx, ty float64)\nInvertY()\n```\n\nIt is often desired to rotate or scale about a point that is not the origin. The functions `RotateAbout`, `ScaleAbout`, `ShearAbout` are provided as a convenience.\n\n`InvertY` is provided in case Y should increase from bottom to top vs. the default top to bottom.\n\n## Stack Functions\n\nSave and restore the state of the context. These can be nested.\n\n```go\nPush()\nPop()\n```\n\n## Clipping Functions\n\nUse clipping regions to restrict drawing operations to an area that you\ndefined using paths.\n\n```go\nClip()\nClipPreserve()\nResetClip()\nAsMask() *image.Alpha\nSetMask(mask *image.Alpha)\nInvertMask()\n```\n\n## Helper Functions\n\nSometimes you just don't want to write these yourself.\n\n```go\nRadians(degrees float64) float64\nDegrees(radians float64) float64\nLoadImage(path string) (image.Image, error)\nLoadPNG(path string) (image.Image, error)\nSavePNG(path string, im image.Image) error\n```\n\n![Separator](http://i.imgur.com/fsUvnPB.png)\n\n## Another Example\n\nSee the output of this example below.\n\n```go\npackage main\n\nimport \"github.com/fogleman/gg\"\n\nfunc main() {\n\tconst S = 1024\n\tdc := gg.NewContext(S, S)\n\tdc.SetRGBA(0, 0, 0, 0.1)\n\tfor i := 0; i \u003c 360; i += 15 {\n\t\tdc.Push()\n\t\tdc.RotateAbout(gg.Radians(float64(i)), S/2, S/2)\n\t\tdc.DrawEllipse(S/2, S/2, S*7/16, S/8)\n\t\tdc.Fill()\n\t\tdc.Pop()\n\t}\n\tdc.SavePNG(\"out.png\")\n}\n```\n\n![Ellipses](http://i.imgur.com/J9CBZef.png)\n","funding_links":[],"categories":["开源类库","Go","图片","Images","Open source library","Images 图像处理","Relational Databases","rendering","Programming Languages","Programming","\u003cspan id=\"图片-images\"\u003e图片 Images\u003c/span\u003e","图片处理库","图像","Libraries","圖象"],"sub_categories":["图形处理","检索及分析资料库","Miscs","Advanced Console UIs","Search and Analytic Databases","Graphics Processing","SQL 查询语句构建库","Go","Golang","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","交互工具","交流","高級控制台界面","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffogleman%2Fgg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffogleman%2Fgg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffogleman%2Fgg/lists"}