Last active
August 29, 2015 14:00
-
-
Save justinfx/33931727822fbebc4aa5 to your computer and use it in GitHub Desktop.
comparing OpenImageIGO to iMagick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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