{"id":13413184,"url":"https://github.com/disintegration/gift","last_synced_at":"2025-05-14T04:06:50.596Z","repository":{"id":18571305,"uuid":"21774052","full_name":"disintegration/gift","owner":"disintegration","description":"Go Image Filtering Toolkit","archived":false,"fork":false,"pushed_at":"2023-09-20T07:18:58.000Z","size":1239,"stargazers_count":1769,"open_issues_count":5,"forks_count":120,"subscribers_count":48,"default_branch":"master","last_synced_at":"2025-04-10T20:55:43.333Z","etag":null,"topics":["filters","go","image","image-processing"],"latest_commit_sha":null,"homepage":null,"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/disintegration.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2014-07-12T18:47:40.000Z","updated_at":"2025-04-09T15:17:25.000Z","dependencies_parsed_at":"2024-01-08T15:34:36.733Z","dependency_job_id":null,"html_url":"https://github.com/disintegration/gift","commit_stats":{"total_commits":103,"total_committers":6,"mean_commits":"17.166666666666668","dds":0.3398058252427184,"last_synced_commit":"575e249f241f574659e4495fb306c04f86340c13"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/disintegration%2Fgift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/disintegration%2Fgift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/disintegration%2Fgift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/disintegration%2Fgift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/disintegration","download_url":"https://codeload.github.com/disintegration/gift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254067668,"owners_count":22009233,"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":["filters","go","image","image-processing"],"created_at":"2024-07-30T20:01:34.642Z","updated_at":"2025-05-14T04:06:45.542Z","avatar_url":"https://github.com/disintegration.png","language":"Go","readme":"# GO IMAGE FILTERING TOOLKIT (GIFT)\n\n[![GoDoc](https://godoc.org/github.com/disintegration/gift?status.svg)](https://godoc.org/github.com/disintegration/gift)\n[![Build Status](https://travis-ci.org/disintegration/gift.svg?branch=master)](https://travis-ci.org/disintegration/gift)\n[![Coverage Status](https://coveralls.io/repos/github/disintegration/gift/badge.svg?branch=master)](https://coveralls.io/github/disintegration/gift?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/disintegration/gift)](https://goreportcard.com/report/github.com/disintegration/gift)\n\n\n*Package gift provides a set of useful image processing filters.*\n\nPure Go. No external dependencies outside of the Go standard library.\n\n\n### INSTALLATION / UPDATING\n\n    go get -u github.com/disintegration/gift\n\n\n### DOCUMENTATION\n\nhttp://godoc.org/github.com/disintegration/gift\n\n\n### QUICK START\n\n```go\n// 1. Create a new filter list and add some filters.\ng := gift.New(\n\tgift.Resize(800, 0, gift.LanczosResampling),\n\tgift.UnsharpMask(1, 1, 0),\n)\n\n// 2. Create a new image of the corresponding size.\n// dst is a new target image, src is the original image.\ndst := image.NewRGBA(g.Bounds(src.Bounds()))\n\n// 3. Use the Draw func to apply the filters to src and store the result in dst.\ng.Draw(dst, src)\n```\n\n### USAGE\n\nTo create a sequence of filters, the `New` function is used:\n```go\ng := gift.New(\n\tgift.Grayscale(),\n\tgift.Contrast(10),\n)\n```\nFilters also can be added using the `Add` method:\n```go\ng.Add(GaussianBlur(2))\n```\n\nThe `Bounds` method takes the bounds of the source image and returns appropriate bounds for the destination image to fit the result (for example, after using `Resize` or `Rotate` filters).\n\n```go\ndst := image.NewRGBA(g.Bounds(src.Bounds()))\n```\n\nThere are two methods available to apply these filters to an image:\n\n- `Draw` applies all the added filters to the src image and outputs the result to the dst image starting from the top-left corner (Min point).\n```go\ng.Draw(dst, src)\n```\n\n- `DrawAt` provides more control. It outputs the filtered src image to the dst image at the specified position using the specified image composition operator. This example is equivalent to the previous:\n```go\ng.DrawAt(dst, src, dst.Bounds().Min, gift.CopyOperator)\n```\n\nTwo image composition operators are supported by now:\n- `CopyOperator` - Replaces pixels of the dst image with pixels of the filtered src image. This mode is used by the Draw method.\n- `OverOperator` - Places the filtered src image on top of the dst image. This mode makes sence if the filtered src image has transparent areas.\n\nEmpty filter list can be used to create a copy of an image or to paste one image to another. For example:\n```go\n// Create a new image with dimensions of the bgImage.\ndstImage := image.NewRGBA(bgImage.Bounds())\n// Copy the bgImage to the dstImage.\ngift.New().Draw(dstImage, bgImage)\n// Draw the fgImage over the dstImage at the (100, 100) position.\ngift.New().DrawAt(dstImage, fgImage, image.Pt(100, 100), gift.OverOperator)\n```\n\n\n### SUPPORTED FILTERS\n\n+ Transformations\n\n    - Crop(rect image.Rectangle)\n    - CropToSize(width, height int, anchor Anchor)\n    - FlipHorizontal()\n    - FlipVertical()\n    - Resize(width, height int, resampling Resampling)\n    - ResizeToFill(width, height int, resampling Resampling, anchor Anchor)\n    - ResizeToFit(width, height int, resampling Resampling)\n    - Rotate(angle float32, backgroundColor color.Color, interpolation Interpolation)\n    - Rotate180()\n    - Rotate270()\n    - Rotate90()\n    - Transpose()\n    - Transverse()\n\n+ Adjustments \u0026 effects\n\n    - Brightness(percentage float32)\n    - ColorBalance(percentageRed, percentageGreen, percentageBlue float32)\n    - ColorFunc(fn func(r0, g0, b0, a0 float32) (r, g, b, a float32))\n    - Colorize(hue, saturation, percentage float32)\n    - ColorspaceLinearToSRGB()\n    - ColorspaceSRGBToLinear()\n    - Contrast(percentage float32)\n    - Convolution(kernel []float32, normalize, alpha, abs bool, delta float32)\n    - Gamma(gamma float32)\n    - GaussianBlur(sigma float32)\n    - Grayscale()\n    - Hue(shift float32)\n    - Invert()\n    - Maximum(ksize int, disk bool)\n    - Mean(ksize int, disk bool)\n    - Median(ksize int, disk bool)\n    - Minimum(ksize int, disk bool)\n    - Pixelate(size int)\n    - Saturation(percentage float32)\n    - Sepia(percentage float32)\n    - Sigmoid(midpoint, factor float32)\n    - Sobel()\n    - Threshold(percentage float32)\n    - UnsharpMask(sigma, amount, threshold float32)\n\n\n### FILTER EXAMPLES\n\nThe original image:\n\n![](testdata/src.png)\n\nResulting images after applying some of the filters:\n\n name / result                              | name / result                              | name / result                              | name / result\n--------------------------------------------|--------------------------------------------|--------------------------------------------|--------------------------------------------\nresize                                      | crop_to_size                               | rotate_180                                 | rotate_30\n![](testdata/dst_resize.png)                | ![](testdata/dst_crop_to_size.png)         | ![](testdata/dst_rotate_180.png)           | ![](testdata/dst_rotate_30.png)\nbrightness_increase                         | brightness_decrease                        | contrast_increase                          | contrast_decrease\n![](testdata/dst_brightness_increase.png)   | ![](testdata/dst_brightness_decrease.png)  | ![](testdata/dst_contrast_increase.png)    | ![](testdata/dst_contrast_decrease.png)\nsaturation_increase                         | saturation_decrease                        | gamma_1.5                                  | gamma_0.5\n![](testdata/dst_saturation_increase.png)   | ![](testdata/dst_saturation_decrease.png)  | ![](testdata/dst_gamma_1.5.png)            | ![](testdata/dst_gamma_0.5.png)\ngaussian_blur                               | unsharp_mask                               | sigmoid                                    | pixelate\n![](testdata/dst_gaussian_blur.png)         | ![](testdata/dst_unsharp_mask.png)         | ![](testdata/dst_sigmoid.png)              | ![](testdata/dst_pixelate.png)\ncolorize                                    | grayscale                                  | sepia                                      | invert\n![](testdata/dst_colorize.png)              | ![](testdata/dst_grayscale.png)            | ![](testdata/dst_sepia.png)                | ![](testdata/dst_invert.png)\nmean                                        | median                                     | minimum                                    | maximum\n![](testdata/dst_mean.png)                  | ![](testdata/dst_median.png)               | ![](testdata/dst_minimum.png)              | ![](testdata/dst_maximum.png)\nhue_rotate                                  | color_balance                              | color_func                                 | convolution_emboss\n![](testdata/dst_hue_rotate.png)            | ![](testdata/dst_color_balance.png)        | ![](testdata/dst_color_func.png)           | ![](testdata/dst_convolution_emboss.png)\n\nHere's the code that produces the above images:\n\n```go\npackage main\n\nimport (\n\t\"image\"\n\t\"image/color\"\n\t\"image/png\"\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/disintegration/gift\"\n)\n\nfunc main() {\n\tsrc := loadImage(\"testdata/src.png\")\n\n\tfilters := map[string]gift.Filter{\n\t\t\"resize\":               gift.Resize(100, 0, gift.LanczosResampling),\n\t\t\"crop_to_size\":         gift.CropToSize(100, 100, gift.LeftAnchor),\n\t\t\"rotate_180\":           gift.Rotate180(),\n\t\t\"rotate_30\":            gift.Rotate(30, color.Transparent, gift.CubicInterpolation),\n\t\t\"brightness_increase\":  gift.Brightness(30),\n\t\t\"brightness_decrease\":  gift.Brightness(-30),\n\t\t\"contrast_increase\":    gift.Contrast(30),\n\t\t\"contrast_decrease\":    gift.Contrast(-30),\n\t\t\"saturation_increase\":  gift.Saturation(50),\n\t\t\"saturation_decrease\":  gift.Saturation(-50),\n\t\t\"gamma_1.5\":            gift.Gamma(1.5),\n\t\t\"gamma_0.5\":            gift.Gamma(0.5),\n\t\t\"gaussian_blur\":        gift.GaussianBlur(1),\n\t\t\"unsharp_mask\":         gift.UnsharpMask(1, 1, 0),\n\t\t\"sigmoid\":              gift.Sigmoid(0.5, 7),\n\t\t\"pixelate\":             gift.Pixelate(5),\n\t\t\"colorize\":             gift.Colorize(240, 50, 100),\n\t\t\"grayscale\":            gift.Grayscale(),\n\t\t\"sepia\":                gift.Sepia(100),\n\t\t\"invert\":               gift.Invert(),\n\t\t\"mean\":                 gift.Mean(5, true),\n\t\t\"median\":               gift.Median(5, true),\n\t\t\"minimum\":              gift.Minimum(5, true),\n\t\t\"maximum\":              gift.Maximum(5, true),\n\t\t\"hue_rotate\":           gift.Hue(45),\n\t\t\"color_balance\":        gift.ColorBalance(10, -10, -10),\n\t\t\"color_func\": gift.ColorFunc(\n\t\t\tfunc(r0, g0, b0, a0 float32) (r, g, b, a float32) {\n\t\t\t\tr = 1 - r0   // invert the red channel\n\t\t\t\tg = g0 + 0.1 // shift the green channel by 0.1\n\t\t\t\tb = 0        // set the blue channel to 0\n\t\t\t\ta = a0       // preserve the alpha channel\n\t\t\t\treturn r, g, b, a\n\t\t\t},\n\t\t),\n\t\t\"convolution_emboss\": gift.Convolution(\n\t\t\t[]float32{\n\t\t\t\t-1, -1, 0,\n\t\t\t\t-1, 1, 1,\n\t\t\t\t0, 1, 1,\n\t\t\t},\n\t\t\tfalse, false, false, 0.0,\n\t\t),\n\t}\n\n\tfor name, filter := range filters {\n\t\tg := gift.New(filter)\n\t\tdst := image.NewNRGBA(g.Bounds(src.Bounds()))\n\t\tg.Draw(dst, src)\n\t\tsaveImage(\"testdata/dst_\"+name+\".png\", dst)\n\t}\n}\n\nfunc loadImage(filename string) image.Image {\n\tf, err := os.Open(filename)\n\tif err != nil {\n\t\tlog.Fatalf(\"os.Open failed: %v\", err)\n\t}\n\tdefer f.Close()\n\timg, _, err := image.Decode(f)\n\tif err != nil {\n\t\tlog.Fatalf(\"image.Decode failed: %v\", err)\n\t}\n\treturn img\n}\n\nfunc saveImage(filename string, img image.Image) {\n\tf, err := os.Create(filename)\n\tif err != nil {\n\t\tlog.Fatalf(\"os.Create failed: %v\", err)\n\t}\n\tdefer f.Close()\n\terr = png.Encode(f, img)\n\tif err != nil {\n\t\tlog.Fatalf(\"png.Encode failed: %v\", err)\n\t}\n}\n```\n","funding_links":[],"categories":["Images 图像处理","Images","开源类库","Misc","Relational Databases","图片","Go","Open source library","圖象","\u003cspan id=\"图片-images\"\u003e图片 Images\u003c/span\u003e","图像","Repositories"],"sub_categories":["SQL 查询语句构建库","Advanced Console UIs","图形处理","检索及分析资料库","Graphics Processing","Search and Analytic Databases","高級控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","交流","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdisintegration%2Fgift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdisintegration%2Fgift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdisintegration%2Fgift/lists"}