{"id":13547138,"url":"https://github.com/nfnt/resize","last_synced_at":"2025-10-05T20:30:48.398Z","repository":{"id":4162208,"uuid":"5277074","full_name":"nfnt/resize","owner":"nfnt","description":"Pure golang image resizing ","archived":true,"fork":false,"pushed_at":"2022-04-02T06:46:33.000Z","size":123,"stargazers_count":3017,"open_issues_count":12,"forks_count":321,"subscribers_count":76,"default_branch":"master","last_synced_at":"2024-09-30T21:41:28.185Z","etag":null,"topics":["go","image-processing","resize"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nfnt.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}},"created_at":"2012-08-02T19:48:26.000Z","updated_at":"2024-09-30T14:41:52.000Z","dependencies_parsed_at":"2022-07-10T02:46:04.482Z","dependency_job_id":null,"html_url":"https://github.com/nfnt/resize","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfnt%2Fresize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfnt%2Fresize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfnt%2Fresize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfnt%2Fresize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nfnt","download_url":"https://codeload.github.com/nfnt/resize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235440460,"owners_count":18990708,"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":["go","image-processing","resize"],"created_at":"2024-08-01T12:00:51.476Z","updated_at":"2025-10-05T20:30:43.140Z","avatar_url":"https://github.com/nfnt.png","language":"Go","readme":"# This package is no longer being updated! Please look for alternatives if that bothers you.\n\nResize\n======\n\nImage resizing for the [Go programming language](http://golang.org) with common interpolation methods.\n\n[![Build Status](https://travis-ci.org/nfnt/resize.svg)](https://travis-ci.org/nfnt/resize)\n\nInstallation\n------------\n\n```bash\n$ go get github.com/nfnt/resize\n```\n\nIt's that easy!\n\nUsage\n-----\n\nThis package needs at least Go 1.1. Import package with\n\n```go\nimport \"github.com/nfnt/resize\"\n```\n\nThe resize package provides 2 functions:\n\n* `resize.Resize` creates a scaled image with new dimensions (`width`, `height`) using the interpolation function `interp`.\n  If either `width` or `height` is set to 0, it will be set to an aspect ratio preserving value.\n* `resize.Thumbnail` downscales an image preserving its aspect ratio to the maximum dimensions (`maxWidth`, `maxHeight`).\n  It will return the original image if original sizes are smaller than the provided dimensions.\n\n```go\nresize.Resize(width, height uint, img image.Image, interp resize.InterpolationFunction) image.Image\nresize.Thumbnail(maxWidth, maxHeight uint, img image.Image, interp resize.InterpolationFunction) image.Image\n```\n\nThe provided interpolation functions are (from fast to slow execution time)\n\n- `NearestNeighbor`: [Nearest-neighbor interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation)\n- `Bilinear`: [Bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation)\n- `Bicubic`: [Bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation)\n- `MitchellNetravali`: [Mitchell-Netravali interpolation](http://dl.acm.org/citation.cfm?id=378514)\n- `Lanczos2`: [Lanczos resampling](http://en.wikipedia.org/wiki/Lanczos_resampling) with a=2\n- `Lanczos3`: [Lanczos resampling](http://en.wikipedia.org/wiki/Lanczos_resampling) with a=3\n\nWhich of these methods gives the best results depends on your use case.\n\nSample usage:\n\n```go\npackage main\n\nimport (\n\t\"github.com/nfnt/resize\"\n\t\"image/jpeg\"\n\t\"log\"\n\t\"os\"\n)\n\nfunc main() {\n\t// open \"test.jpg\"\n\tfile, err := os.Open(\"test.jpg\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// decode jpeg into image.Image\n\timg, err := jpeg.Decode(file)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfile.Close()\n\n\t// resize to width 1000 using Lanczos resampling\n\t// and preserve aspect ratio\n\tm := resize.Resize(1000, 0, img, resize.Lanczos3)\n\n\tout, err := os.Create(\"test_resized.jpg\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer out.Close()\n\n\t// write new image to file\n\tjpeg.Encode(out, m, nil)\n}\n```\n\nCaveats\n-------\n\n* Optimized access routines are used for `image.RGBA`, `image.NRGBA`, `image.RGBA64`, `image.NRGBA64`, `image.YCbCr`, `image.Gray`, and `image.Gray16` types. All other image types are accessed in a generic way that will result in slow processing speed.\n* JPEG images are stored in `image.YCbCr`. This image format stores data in a way that will decrease processing speed. A resize may be up to 2 times slower than with `image.RGBA`. \n\n\nDownsizing Samples\n-------\n\nDownsizing is not as simple as it might look like. Images have to be filtered before they are scaled down, otherwise aliasing might occur.\nFiltering is highly subjective: Applying too much will blur the whole image, too little will make aliasing become apparent.\nResize tries to provide sane defaults that should suffice in most cases.\n\n### Artificial sample\n\nOriginal image\n![Rings](http://nfnt.github.com/img/rings_lg_orig.png)\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003cth\u003e\u003cimg src=\"http://nfnt.github.com/img/rings_300_NearestNeighbor.png\" /\u003e\u003cbr\u003eNearest-Neighbor\u003c/th\u003e\n\u003cth\u003e\u003cimg src=\"http://nfnt.github.com/img/rings_300_Bilinear.png\" /\u003e\u003cbr\u003eBilinear\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003cth\u003e\u003cimg src=\"http://nfnt.github.com/img/rings_300_Bicubic.png\" /\u003e\u003cbr\u003eBicubic\u003c/th\u003e\n\u003cth\u003e\u003cimg src=\"http://nfnt.github.com/img/rings_300_MitchellNetravali.png\" /\u003e\u003cbr\u003eMitchell-Netravali\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003cth\u003e\u003cimg src=\"http://nfnt.github.com/img/rings_300_Lanczos2.png\" /\u003e\u003cbr\u003eLanczos2\u003c/th\u003e\n\u003cth\u003e\u003cimg src=\"http://nfnt.github.com/img/rings_300_Lanczos3.png\" /\u003e\u003cbr\u003eLanczos3\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n### Real-Life sample\n\nOriginal image  \n![Original](http://nfnt.github.com/img/IMG_3694_720.jpg)\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003cth\u003e\u003cimg src=\"http://nfnt.github.com/img/IMG_3694_300_NearestNeighbor.png\" /\u003e\u003cbr\u003eNearest-Neighbor\u003c/th\u003e\n\u003cth\u003e\u003cimg src=\"http://nfnt.github.com/img/IMG_3694_300_Bilinear.png\" /\u003e\u003cbr\u003eBilinear\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003cth\u003e\u003cimg src=\"http://nfnt.github.com/img/IMG_3694_300_Bicubic.png\" /\u003e\u003cbr\u003eBicubic\u003c/th\u003e\n\u003cth\u003e\u003cimg src=\"http://nfnt.github.com/img/IMG_3694_300_MitchellNetravali.png\" /\u003e\u003cbr\u003eMitchell-Netravali\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003cth\u003e\u003cimg src=\"http://nfnt.github.com/img/IMG_3694_300_Lanczos2.png\" /\u003e\u003cbr\u003eLanczos2\u003c/th\u003e\n\u003cth\u003e\u003cimg src=\"http://nfnt.github.com/img/IMG_3694_300_Lanczos3.png\" /\u003e\u003cbr\u003eLanczos3\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n\nLicense\n-------\n\nCopyright (c) 2012 Jan Schlicht \u003cjanschlicht@gmail.com\u003e\nResize is released under a MIT style license.\n","funding_links":[],"categories":["Go","图像","Images","Relational Databases","Images 图像处理","Imagery","Repositories","圖象","\u003cspan id=\"图片-images\"\u003e图片 Images\u003c/span\u003e","图片"],"sub_categories":["高级控制台界面","Advanced Console UIs","Search and Analytic Databases","SQL 查询语句构建库","Middlewares","高級控制台界面","交流","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","检索及分析资料库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfnt%2Fresize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnfnt%2Fresize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfnt%2Fresize/lists"}