|
|
|
|
|
by hierro
4648 days ago
|
|
Go's image module is painfully slow, supports a limited set of formats and fails on lots of optimized images. I also have implemented this in Go, but using cgo and graphicksmagicks, which is way faster and decodes almost any image you throw at it (there are some issues with very optimized GIFs, but I fallback to gifsoup for "deoptimizing" them in those cases). In fact, I even added a function for cropping and resizing an image to a given size in the module itself (since I think is a very common need), while keeping the aspect ratio and also giving the option to just center the result or grab the part of the image with higher entropy (e.g. suppose you have an image with a person in the side and then a lot of blue sky, you probably don't want to crop and image and end up with just sky in the thumbnail). This is just one of a few benchmarks I wrote: BenchmarkResizePngMagick 20 80665091 ns/op 689 B/op 3 allocs/op BenchmarkResizePngNative 1 9689016519 ns/op 351200 B/op 27 allocs/op (yup, that's 120x faster) The bindings are mostly documented, but I haven't gotten around to releasing the code yet, although I do hope do publish it soon. If you're interested, send me an email and I'll let you know when I put the code in Github. |
|