{"id":13574312,"url":"https://github.com/fawick/speedtest-resize","last_synced_at":"2025-04-13T23:28:15.145Z","repository":{"id":45519216,"uuid":"12866970","full_name":"fawick/speedtest-resize","owner":"fawick","description":"Compare various Image resize algorithms for the Go language","archived":false,"fork":false,"pushed_at":"2020-10-28T16:26:39.000Z","size":46,"stargazers_count":243,"open_issues_count":1,"forks_count":18,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-04T14:38:29.729Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fawick.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":"2013-09-16T12:40:05.000Z","updated_at":"2025-03-18T15:04:14.000Z","dependencies_parsed_at":"2022-09-03T02:00:11.380Z","dependency_job_id":null,"html_url":"https://github.com/fawick/speedtest-resize","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fawick%2Fspeedtest-resize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fawick%2Fspeedtest-resize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fawick%2Fspeedtest-resize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fawick%2Fspeedtest-resize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fawick","download_url":"https://codeload.github.com/fawick/speedtest-resize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248795687,"owners_count":21162821,"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":[],"created_at":"2024-08-01T15:00:50.182Z","updated_at":"2025-04-13T23:28:15.121Z","avatar_url":"https://github.com/fawick.png","language":"Go","funding_links":[],"categories":["Benchmarks","Go","基准","基准点","基准测试","基準測試","Twitter"],"sub_categories":["Other Software","其他软件","其他軟件"],"readme":"speedtest-resize\n================\n\nCompare various Image resize algorithms for the Go language\n\nI am writing a web gallery called gonagall in Go\n(https://github.com/fawick/gonagall). For that, I need a efficient solution for\nscaling and resizing a lot of images (mostly JPGs) to generate thumbnails and\nbandwidth-friendly sized copies from high-resolution original photo files.\n\nIn this project I compare the speed of a few selected image resizing algorithms\nwith each other as well as with ImageMagick and GraphicsMagick. The competitors\nare\n\n- https://github.com/nfnt/resize, Pure golang image resizing, more precisely\n  only Nearest-Neighbor interpolation that comes with that Go package.\n- https://github.com/disintegration/gift Again, I use one of the fastest\n  algorithms of the package. Here, it's called 'Box'\n- https://github.com/disintegration/imaging Again, I use one of the fastest\n  algorithms of the package. Here, it's called 'Box'\n- https://github.com/anthonynsimon/bild A collection of parallel image\n  processing algorithms in pure Go ('NearestNeighbor' algorithm)\n- [ImageMagick convert](http://www.imagemagick.org/script/convert.php) with the options `-resize 150x150\u003e`\n- [ImageMagick convert](http://www.imagemagick.org/script/convert.php) with the\n  options `-define \"jpeg:size=300x300 -thumbnail 150x150\u003e`. `-thumbnail` is\nconsidered to be faster than resize, and the `-define` will reduce the size (in\nterms of memory footprint) of the original image on reading.\n- [GraphicsMagick convert](http://www.graphicsmagick.org/convert.html) with the\n  options `-define \"jpeg:size=300x300 -thumbnail 150x150\u003e`.\n- https://github.com/gographics/imagick Go wrapper for the MagickWand API,\n  again the Box algorithm is used for the sake of comparing the results.\n- https://github.com/lazywei/go-opencv Go binding for OpenCV, using the fastest\n  algorithm.\n- https://github.com/bamiaux/rez, pure go resizer, using bilinear interpolation\n  in these tests\n- https://github.com/DAddYE/vips, bindings for libvips\n  (http://www.vips.ecs.soton.ac.uk/index.php?title=Libvips)\n- https://github.com/daddye/trez, an image resizer build on top of OpenCV and\n  jpeg-turbo\n- https://camlistore.org/pkg/images/fastjpeg, package fastjpeg uses djpeg(1),\n  from the Independent JPEG Group's (www.ijg.org) jpeg package, to quickly\n  down-sample images on load\n- External command `vipsthumbnail` with parameters `-s 150`\n  (https://github.com/libvips/libvips)\n- External command `epeg` with parameters `-m 150`\n  (https://github.com/mattes/epeg)\n\n### Installation\n\nTo run the tests `go get` the source and compile/run it:\n\n    $ go get -u github.com/fawick/speedtest-resize -tags all\n    $ cd $GOPATH/src/speedtest-resize\n    $ go run main.go \u003cjpg file folder\u003e\n\nAlternatively, call the go command (or the compiled binary) from the image\nfolder without supplying a parameter\n\n    $ cd \u003cjpg file folder\u003e\n    $ go run $GOPATH/src/speedtest-resize/main.go\n\nA the package requires different 3rdparty libraries to be installed, you can\nuse build tags to control what libraries to use. The following build tags are\navailable:\n\n| Tag         | Description                                             |\n| ----------- | ------------------------------------------------------- |\n| `opencv`    | Include `lazywei/go-opencv` in the tests.               |\n| `imagick`   | Include `gographics/imagick` in the tests.              |\n| `vips`      | Include `DAddYE/vips in the tests`.                     |\n| `fastjpeg`  | Include `camlistore/fastjpeg in the tests`.             |\n| `all`       | An alias for `opencv imagick fastjpeg vips`.            |\n| `nopure`    | Don't include the Pure Golang packages                  |\n| `noexec`    | Don't run the tests that execute other programs.        |\n\nThe default `go get` without any tags will try the packages that are pure go\nand the external programs but not use any non-Go library.\n\n### Benchmark\n\nIm my test scenario all of these tools/packages are unleashed on a directory\ncontaining JPG photo files, all of which have a resolution of 5616x3744 pixels\n(aspect ratio 2:1, both landscape and portrait).\n\nFor each tool/package and for all files, the total time for loading the\noriginal file, scaling the image to a thumbnail of 150x100 pixels, and writing\nit to a new JPG file is measured. In the end, the total runtime for processing\nthe 10 first files and the average time per file is printed for each\ntool/package.\n\nThe scenario is run on a Intel(R) Pentium(R) Dual T2390 @ 1.86GHz running\nUbuntu 14.04. Here are the results:\n\n| Table                 | Time (avg.) | Size (avg.) | Pure Go |\n|-----------------------|------------:|------------:|:-------:|\n| vipsthumbnail         |      0.120s |      0.065% |         |\n| ImageMagick_thumbnail |      0.326s |      0.242% |         |\n| vips                  |      0.339s |      0.100% |         |\n| magickwand_box        |      1.148s |      0.538% |         |\n| ImageMagick_resize    |      2.316s |      0.626% |         |\n| rez_bilinear          |      2.913s |      0.053% |    X    |\n| Nfnt_NearestNeighbor  |      3.498s |      0.057% |    X    |\n| imaging_box           |      4.734s |      0.057% |    X    |\n| gift_box              |      4.746s |      0.057% |    X    |\n\n\n--------\n\nYet another scenario ran by [lazywei](https://github.com/lazywei), 2.5GHz Intel Core i5, Mac OS X 10.9.1:\n\n| Tables               | Average time per file  |\n| -------------------- | ----------------------:|\n| magickwand_box       |  155.371531ms          |\n| imaging_Box          |  463.459339ms          |\n| Nfnt_NearestNeighbor |  1.436507946s          |\n| OpenCv               |   97.353041ms          |\n\n--------\n\nYet another scenario ran by [bamiaux](https://github.com/bamiaux), 3.3GHz Intel Core i5, win 7:\n\n| Tables               | Average time per file  |\n| -------------------- | ----------------------:|\n| rez_bilinear         |  148ms                 |\n| imaging_Box          |  243ms                 |\n| Nfnt_NearestNeighbor |  233ms                 |\n\n--------\n\nA new scenario ran by [nono](https://github.com/nono), 3.4GHz Intel Core i7, Ubuntu 16.10:\n\n| Table                          | Time (file avg.) | Size (file avg.) | Pure Go |\n|--------------------------------|-----------------:|-----------------:|:-------:|\n| ImageMagick_thumbnail          |           0.057s |           0.361% |         |\n| vips                           |           0.070s |           0.260% |         |\n| epeg                           |           0.079s |           0.207% |         |\n| fastjpeg                       |           0.082s |           0.186% |         |\n| opencv                         |           0.110s |           0.597% |         |\n| vipsthumbnail                  |           0.115s |           0.441% |         |\n| GraphicsMagick_thumbnail       |           0.172s |           0.427% |         |\n| magickwand_box                 |           0.190s |           0.575% |         |\n| T-REZ                          |           0.204s |           0.323% |         |\n| rez_bilinear                   |           0.349s |           0.140% |    X    |\n| x_image_draw                   |           0.370s |           0.160% |    X    |\n| imaging_box                    |           0.439s |           0.146% |    X    |\n| gift_box                       |           0.440s |           0.146% |    X    |\n| Nfnt_NearestNeighbor           |           0.447s |           0.146% |    X    |\n| bild_resize                    |           0.515s |           0.206% |    X    |\n| ImageMagick_resize             |           0.568s |           0.542% |         |\n\n--------\n\nSo, what is to learn from that? While all of the currently existing\npure-Go-language solutions do a pretty good job in generating good-looking\nthumbnails, they are much slower than the veteran dedicated image processing\ntoolboxes. That is hardly surprising, given that both ImageMagick and\nGraphicsMagick have been around for decades and have been optimized to work as\nefficient as possible. Go and its image processing packages are still the new\nkids on the block, and while they work pretty neat for the occasional tweak of\nan image or two, I rather not use them as the default image processor in\n[gonagall](http://github.com/fawick/gonagall) yet.\n\nI was surprised to find that GraphicsMagick was slower than ImageMagick in my\ntest scenario, as I expected it to be exactly the other way around with\nGraphicsMagick's fancy multi-processor algorithms.\n\nWhile the imagick Wrapper is written in Go, it uses CGO bindings of the C\nMagickWand API. It outperforms the pure-Go approaches (five times faster than\nhttp://github.com/disintegration/imaging) but it still slower than calling\nImageMagick in an external process. Of the above 1.13 seconds, only around 275\nmillisecs were used for resizing and saving an individual file, while over 850\nms were used by simply loading the file. I wonder how much optimization can\nstill be done in the imagick loading routines.\n\nHoly cow! `vipsthumbnail` __is__ blazing fast.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffawick%2Fspeedtest-resize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffawick%2Fspeedtest-resize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffawick%2Fspeedtest-resize/lists"}