https://github.com/sebnyberg/imgcrop
Efficient cropping of large images
https://github.com/sebnyberg/imgcrop
bmp image-processing
Last synced: about 1 month ago
JSON representation
Efficient cropping of large images
- Host: GitHub
- URL: https://github.com/sebnyberg/imgcrop
- Owner: sebnyberg
- Created: 2023-03-15T20:32:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2026-03-30T16:22:17.000Z (3 months ago)
- Last Synced: 2026-05-04T21:45:25.698Z (about 2 months ago)
- Topics: bmp, image-processing
- Language: Go
- Homepage:
- Size: 812 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# imgcrop
Library for efficient cropping of very large images.
See [Design Doc](./docs/DESIGN.md) for background and design considerations.
## Stability
:warning: This package is under development and in flux. :warning:
## Installation
```shell
go get github.com/sebnyberg/imgcrop
```
## Usage
```go
src, err := os.Open("big.bmp")
if err != nil {
return err
}
dst, err := os.Open("cropped.bmp")
if err != nil {
return err
}
offx := 5500
offy := 7500
width := 1500
height := 2000
region := image.Rect(offx, offy, width, height)
err = bmpx.Crop(src, dest, region)
if err != nil {
return err
}
```
## Performance
Benchmark that crops different sizes from a 1.2GiB 29566x14321 px image and stores the result in an output file, randomizing x- and y-offset with each crop:
```
go test -test.v -test.run=NONE -test.bench='^\QBenchmarkBMP\E$'
goos: linux
goarch: amd64
pkg: github.com/sebnyberg/imgcrop/bmpx
cpu: Intel(R) Core(TM) i5-8500 CPU @ 3.00GHz
BenchmarkBMP
BenchmarkBMP/100X100
BenchmarkBMP/100X100-6 1748 613716 ns/op
BenchmarkBMP/100X800
BenchmarkBMP/100X800-6 261 4610897 ns/op
BenchmarkBMP/100X6400
BenchmarkBMP/100X6400-6 32 37329677 ns/op
BenchmarkBMP/800X100
BenchmarkBMP/800X100-6 1609 747651 ns/op
BenchmarkBMP/800X800
BenchmarkBMP/800X800-6 202 6291474 ns/op
BenchmarkBMP/800X6400
BenchmarkBMP/800X6400-6 22 47321119 ns/op
BenchmarkBMP/6400X100
BenchmarkBMP/6400X100-6 636 1881620 ns/op
BenchmarkBMP/6400X800
BenchmarkBMP/6400X800-6 72 15344632 ns/op
BenchmarkBMP/6400X6400
BenchmarkBMP/6400X6400-6 9 130090939 ns/op
PASS
ok github.com/sebnyberg/imgcrop/bmpx 15.100s
```
`
## Examples
* [Cropping PNG (terrible perf)](./examples/png.go)
## Testing
This library has been tested by a friend externally, trust me. :eyes: