{"id":13413173,"url":"https://github.com/h2non/bimg","last_synced_at":"2025-05-11T05:44:54.479Z","repository":{"id":28873156,"uuid":"32397463","full_name":"h2non/bimg","owner":"h2non","description":"Go package for fast high-level image processing powered by libvips C library","archived":false,"fork":false,"pushed_at":"2025-01-23T09:51:09.000Z","size":32246,"stargazers_count":2844,"open_issues_count":175,"forks_count":345,"subscribers_count":42,"default_branch":"master","last_synced_at":"2025-05-11T05:44:47.274Z","etag":null,"topics":["crop","crop-image","golang","image","jpeg","libvips","png","processing","resize","watermark","webp"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/h2non/bimg?tab=doc","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/h2non.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-17T14:14:02.000Z","updated_at":"2025-05-09T12:54:22.000Z","dependencies_parsed_at":"2023-01-16T22:16:42.619Z","dependency_job_id":"64db6c30-5cfa-4ca8-904f-56e47cc60562","html_url":"https://github.com/h2non/bimg","commit_stats":{"total_commits":483,"total_committers":63,"mean_commits":7.666666666666667,"dds":0.2981366459627329,"last_synced_commit":"a14e08d5604db4c866680d816be631d43954371a"},"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fbimg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fbimg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fbimg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fbimg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/h2non","download_url":"https://codeload.github.com/h2non/bimg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253523717,"owners_count":21921818,"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":["crop","crop-image","golang","image","jpeg","libvips","png","processing","resize","watermark","webp"],"created_at":"2024-07-30T20:01:34.464Z","updated_at":"2025-05-11T05:44:54.443Z","avatar_url":"https://github.com/h2non.png","language":"Go","readme":"# bimg [![GoDoc](https://godoc.org/github.com/h2non/bimg?status.svg)](https://godoc.org/github.com/h2non/bimg) [![Coverage Status](https://coveralls.io/repos/github/h2non/bimg/badge.svg?branch=master)](https://coveralls.io/github/h2non/bimg?branch=master) ![License](https://img.shields.io/badge/license-MIT-blue.svg)\n\nSmall [Go](http://golang.org) package for fast high-level image processing using [libvips](https://github.com/jcupitt/libvips) via C bindings, providing a simple [programmatic API](#examples).\n\nbimg was designed to be a small and efficient library supporting common [image operations](#supported-image-operations) such as crop, resize, rotate, zoom or watermark. It can read JPEG, PNG, WEBP natively, and optionally TIFF, PDF, GIF and SVG formats if `libvips@8.3+` is compiled with proper library bindings. Lastly AVIF is supported as of `libvips@8.9+`. For AVIF support `libheif` needs to be [compiled with an applicable AVIF en-/decoder](https://github.com/strukturag/libheif#compiling).\n\nbimg is able to output images as JPEG, PNG and WEBP formats, including transparent conversion across them.\n\nbimg uses internally libvips, a powerful library written in C for image processing which requires a [low memory footprint](https://github.com/jcupitt/libvips/wiki/Speed_and_Memory_Use)\nand it's typically 4x faster than using the quickest ImageMagick and GraphicsMagick settings or Go native `image` package, and in some cases it's even 8x faster processing JPEG images.\n\nIf you're looking for an HTTP based image processing solution, see [imaginary](https://github.com/h2non/imaginary).\n\nbimg was heavily inspired in [sharp](https://github.com/lovell/sharp), its homologous package built for [node.js](http://nodejs.org). bimg is used in production environments processing thousands of images per day.\n\n**v1 notice**: `bimg` introduces some minor breaking changes in `v1` release.\nIf you're using `gopkg.in`, you can still rely in the `v0` without worrying about API breaking changes.\n\n## Contents\n\n- [Supported image operations](#supported-image-operations)\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [Performance](#performance)\n- [Benchmark](#benchmark)\n- [Examples](#examples)\n- [Debugging](#debugging)\n- [API](#api)\n- [Authors](#authors)\n- [Credits](#credits)\n\n## Supported image operations\n\n- Resize\n- Enlarge\n- Crop (including smart crop support, libvips 8.5+)\n- Rotate (with auto-rotate based on EXIF orientation)\n- Flip (with auto-flip based on EXIF metadata)\n- Flop\n- Zoom\n- Thumbnail\n- Extract area\n- Watermark (using text or image)\n- Gaussian blur effect\n- Custom output color space (RGB, grayscale...)\n- Format conversion (with additional quality/compression settings)\n- EXIF metadata (size, alpha channel, profile, orientation...)\n- Trim (libvips 8.6+)\n\n## Prerequisites\n\n- [libvips](https://github.com/libvips/libvips) 8.3+ (8.8+ recommended)\n- C compatible compiler such as gcc 4.6+ or clang 3.0+\n- Go 1.3+\n\n**Note**: \n * `libvips` v8.3+ is required for GIF, PDF and SVG support.\n * `libvips` v8.9+ is required for AVIF support. `libheif` compiled with a AVIF en-/decoder also needs to be present.\n\n## Installation\n\n```bash\ngo get -u github.com/h2non/bimg\n```\n\n### libvips\n\nFollow `libvips` installation instructions:\n\n[https://libvips.github.io/libvips/install.html](https://libvips.github.io/libvips/install.html)\n\n##### Installation script\n\n**Note**: install script is officially deprecated, it might not work as expected. We recommend following [libvips install](https://libvips.github.io/libvips/install.html) instructions.\n\nRun the following script as `sudo` (supports OSX, Debian/Ubuntu, Redhat, Fedora, Amazon Linux):\n```bash\ncurl -s https://raw.githubusercontent.com/h2non/bimg/master/preinstall.sh | sudo bash -\n```\n\nIf you want to take the advantage of [OpenSlide](http://openslide.org/), simply add `--with-openslide` to enable it:\n```bash\ncurl -s https://raw.githubusercontent.com/h2non/bimg/master/preinstall.sh | sudo bash -s --with-openslide\n```\n\nThe [install script](https://github.com/h2non/bimg/blob/master/preinstall.sh) requires `curl` and `pkg-config`.\n\n## Performance\n\nlibvips is probably the fastest open source solution for image processing.\nHere you can see some performance test comparisons for multiple scenarios:\n\n- [libvips speed and memory usage](https://github.com/jcupitt/libvips/wiki/Speed-and-memory-use)\n\n## Benchmark\n\nTested using Go 1.5.1 and libvips-7.42.3 in OSX i7 2.7Ghz\n```\nBenchmarkRotateJpeg-8     \t      20\t  64686945 ns/op\nBenchmarkResizeLargeJpeg-8\t      20\t  63390416 ns/op\nBenchmarkResizePng-8      \t     100\t  18147294 ns/op\nBenchmarkResizeWebP-8     \t     100\t  20836741 ns/op\nBenchmarkConvertToJpeg-8  \t     100\t  12831812 ns/op\nBenchmarkConvertToPng-8   \t      10\t 128901422 ns/op\nBenchmarkConvertToWebp-8  \t      10\t 204027990 ns/op\nBenchmarkCropJpeg-8       \t      30\t  59068572 ns/op\nBenchmarkCropPng-8        \t      10\t 117303259 ns/op\nBenchmarkCropWebP-8       \t      10\t 107060659 ns/op\nBenchmarkExtractJpeg-8    \t      50\t  30708919 ns/op\nBenchmarkExtractPng-8     \t    3000\t    595546 ns/op\nBenchmarkExtractWebp-8    \t    3000\t    386379 ns/op\nBenchmarkZoomJpeg-8       \t      10\t 160005424 ns/op\nBenchmarkZoomPng-8        \t      30\t  44561047 ns/op\nBenchmarkZoomWebp-8       \t      10\t 126732678 ns/op\nBenchmarkWatermarkJpeg-8  \t      20\t  79006133 ns/op\nBenchmarkWatermarPng-8    \t     200\t   8197291 ns/op\nBenchmarkWatermarWebp-8   \t      30\t  49360369 ns/op\n```\n\n## Examples\n\n```go\nimport (\n  \"fmt\"\n  \"os\"\n  \"github.com/h2non/bimg\"\n)\n```\n\n#### Resize\n\n```go\nbuffer, err := bimg.Read(\"image.jpg\")\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nnewImage, err := bimg.NewImage(buffer).Resize(800, 600)\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nsize, err := bimg.NewImage(newImage).Size()\nif size.Width == 800 \u0026\u0026 size.Height == 600 {\n  fmt.Println(\"The image size is valid\")\n}\n\nbimg.Write(\"new.jpg\", newImage)\n```\n\n#### Rotate\n\n```go\nbuffer, err := bimg.Read(\"image.jpg\")\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nnewImage, err := bimg.NewImage(buffer).Rotate(90)\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nbimg.Write(\"new.jpg\", newImage)\n```\n\n#### Convert\n\n```go\nbuffer, err := bimg.Read(\"image.jpg\")\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nnewImage, err := bimg.NewImage(buffer).Convert(bimg.PNG)\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nif bimg.NewImage(newImage).Type() == \"png\" {\n  fmt.Fprintln(os.Stderr, \"The image was converted into png\")\n}\n```\n\n#### Force resize\n\nForce resize operation without preserving the aspect ratio:\n\n```go\nbuffer, err := bimg.Read(\"image.jpg\")\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nnewImage, err := bimg.NewImage(buffer).ForceResize(1000, 500)\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nsize := bimg.Size(newImage)\nif size.Width != 1000 || size.Height != 500 {\n  fmt.Fprintln(os.Stderr, \"Incorrect image size\")\n}\n```\n\n#### Custom colour space (black \u0026 white)\n\n```go\nbuffer, err := bimg.Read(\"image.jpg\")\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nnewImage, err := bimg.NewImage(buffer).Colourspace(bimg.INTERPRETATION_B_W)\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\ncolourSpace, _ := bimg.ImageInterpretation(newImage)\nif colourSpace != bimg.INTERPRETATION_B_W {\n  fmt.Fprintln(os.Stderr, \"Invalid colour space\")\n}\n```\n\n#### Custom options\n\nSee [Options](https://godoc.org/github.com/h2non/bimg#Options) struct to discover all the available fields\n\n```go\noptions := bimg.Options{\n  Width:        800,\n  Height:       600,\n  Crop:         true,\n  Quality:      95,\n  Rotate:       180,\n  Interlace:    true,\n}\n\nbuffer, err := bimg.Read(\"image.jpg\")\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nnewImage, err := bimg.NewImage(buffer).Process(options)\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nbimg.Write(\"new.jpg\", newImage)\n```\n\n#### Watermark\n\n```go\nbuffer, err := bimg.Read(\"image.jpg\")\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nwatermark := bimg.Watermark{\n  Text:       \"Chuck Norris (c) 2315\",\n  Opacity:    0.25,\n  Width:      200,\n  DPI:        100,\n  Margin:     150,\n  Font:       \"sans bold 12\",\n  Background: bimg.Color{255, 255, 255},\n}\n\nnewImage, err := bimg.NewImage(buffer).Watermark(watermark)\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nbimg.Write(\"new.jpg\", newImage)\n```\n\n#### Fluent interface\n\n```go\nbuffer, err := bimg.Read(\"image.jpg\")\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\nimage := bimg.NewImage(buffer)\n\n// first crop image\n_, err := image.CropByWidth(300)\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\n// then flip it\nnewImage, err := image.Flip()\nif err != nil {\n  fmt.Fprintln(os.Stderr, err)\n}\n\n// save the cropped and flipped image\nbimg.Write(\"new.jpg\", newImage)\n```\n\n## Debugging\n\nRun the process passing the `DEBUG` environment variable\n```\nDEBUG=bimg ./app\n```\n\nEnable libvips traces (note that a lot of data will be written in stdout):\n```\nVIPS_TRACE=1 ./app\n```\n\nYou can also dump a core on failure, as [John Cuppit](https://github.com/jcupitt) said:\n```c\ng_log_set_always_fatal(\n                G_LOG_FLAG_RECURSION |\n                G_LOG_FLAG_FATAL |\n                G_LOG_LEVEL_ERROR |\n                G_LOG_LEVEL_CRITICAL |\n                G_LOG_LEVEL_WARNING );\n```\n\nOr set the G_DEBUG environment variable:\n```\nexport G_DEBUG=fatal-warnings,fatal-criticals\n```\n\n## API\n\nSee [godoc reference](https://godoc.org/github.com/h2non/bimg) for detailed API documentation.\n\n## Authors\n\n- [Tomás Aparicio](https://github.com/h2non) - Original author and architect.\n\n## Credits\n\nPeople who recurrently contributed to improve `bimg` in some way.\n\n- [John Cupitt](https://github.com/jcupitt)\n- [Yoan Blanc](https://github.com/greut)\n- [Christophe Eblé](https://github.com/chreble)\n- [Brant Fitzsimmons](https://github.com/bfitzsimmons)\n- [Thomas Meson](https://github.com/zllak)\n\nThank you!\n\n## License\n\nMIT - Tomas Aparicio\n\n[![views](https://sourcegraph.com/api/repos/github.com/h2non/bimg/.counters/views.svg)](https://sourcegraph.com/github.com/h2non/bimg)\n","funding_links":[],"categories":["开源类库","Go","Images","Open source library","图片","圖象","Programming Languages","\u003cspan id=\"图片-images\"\u003e图片 Images\u003c/span\u003e","图像","Images 图像处理","图片处理","Relational Databases"],"sub_categories":["图形处理","Search and Analytic Databases","Advanced Console UIs","Graphics Processing","检索及分析资料库","高級控制台界面","Go","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","交流","SQL 查询语句构建库","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2non%2Fbimg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh2non%2Fbimg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2non%2Fbimg/lists"}