Skip to content

Instantly share code, notes, and snippets.

@justinfx
Last active August 29, 2015 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinfx/33931727822fbebc4aa5 to your computer and use it in GitHub Desktop.
Save justinfx/33931727822fbebc4aa5 to your computer and use it in GitHub Desktop.
comparing OpenImageIGO to iMagick
package main
import (
"github.com/justinfx/imagick/imagick"
"runtime"
)
const (
WIDTH = 320
HEIGHT = 240
)
var (
FilePath string = `/tmp/source.png`
OutPath string = `/tmp/image_test2.png`
)
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
imagick.Initialize()
}
func main() {
mw := imagick.NewMagickWand()
defer mw.Destroy()
err := mw.ReadImage(FilePath)
if err != nil {
panic(err.Error())
}
err = mw.ResizeImage(WIDTH, HEIGHT, imagick.FILTER_LANCZOS, 1)
if err != nil {
panic(err.Error())
}
err = mw.WriteImage(OutPath)
if err != nil {
panic(err.Error())
}
}
package main
import (
"github.com/justinfx/openimageigo"
"runtime"
)
const (
WIDTH = 320
HEIGHT = 240
)
var (
FilePath string = `/tmp/source.png`
OutPath string = `/tmp/image_test.png`
)
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
}
func main() {
cache := oiio.CreateImageCache(true)
src, err := oiio.NewImageBufPathCache(FilePath, cache)
if err != nil {
panic(err.Error())
}
src.Read(true)
orig_spec := src.Spec()
spec := oiio.NewImageSpecSize(WIDTH, HEIGHT, orig_spec.NumChannels(), orig_spec.Format())
dst, err := oiio.NewImageBufSpec(spec)
if err != nil {
panic(err.Error())
}
err = oiio.Resize(dst, src, nil, oiio.GlobalThreads)
if err != nil {
panic(err.Error())
}
err = dst.WriteFile(OutPath, "png")
if err != nil {
panic(err.Error())
}
// println(cache.GetStats(1))
}
$ time ./convert_oiio
real 0m0.214s
user 0m0.904s
sys 0m0.022s
$ time ./convert_imagick
real 0m0.195s
user 0m0.157s
sys 0m0.032s
$ time oiiotool /tmp/source.png -resize 320x240 -o /tmp/image_test3.png
real 0m0.200s
user 0m0.758s
sys 0m0.081s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment