The example of this article describes the Golang image image processing method. Share to everyone for your reference, specific as follows:
Golang processing picture is quite simple, I was too functional quite simple, not a thumbnail method.
Copy Code code as follows:
Package Main
Import (
"FMT"
"OS"
"Image"
"Image/color"
"Image/draw"
"Image/jpeg"
)
Func Main () {
F1, err: = OS. Open ("1.jpg")
If Err!= nil {
Panic (ERR)
}
Defer F1. Close ()
F2, err: = OS. Open ("2.jpg")
If Err!= nil {
Panic (ERR)
}
Defer F2. Close ()
F3, Err: = OS. Create ("3.jpg")
If Err!= nil {
Panic (ERR)
}
Defer F3. Close ()
M1, ERR: = JPEG. Decode (F1)
If Err!= nil {
Panic (ERR)
}
Bounds: = M1. Bounds ()
M2, err: = JPEG. Decode (F2)
If Err!= nil {
Panic (ERR)
}
M: = image. Newrgba (Bounds)
White: = color. rgba{255, 255, 255, 255}
Draw. Draw (M, Bounds, &image). Uniform{white}, image. ZP, Draw. SRC)
Draw. Draw (M, bounds, M1, image. ZP, Draw. SRC)
Draw. Draw (m, image. Rect (MB, m, MB), M2, image. Pt, Draw. SRC)
Err = jpeg. Encode (F3, M, &jpeg). OPTIONS{90})
If Err!= nil {
Panic (ERR)
}
Fmt. Printf ("ok\n")
}
I hope this article will help you with your go language program.