XBR Pixel Scale on Golang
Unfortunately, xbr
algorithm is not being shared in Golang.
So I saw this repository written in JS and implemented it in Go language.
I couldn't solve the 3x
. but 2x
and 4x
operate normally.
Image Compare
- original
- 2x
- 3x
- 4x
Usage
package main
import (
"bytes"
"image"
"image/png"
"log"
"os"
"xbr/scale" // change import
)
func saveImageAsPNG(img image.Image, filename string) error {
outFile, err := os.Create(filename)
if err != nil {
return err
}
defer outFile.Close()
return png.Encode(outFile, img)
}
func main() {
file, err := os.ReadFile("fixture/stand@1x.png")
if err != nil {
log.Fatalln(err)
}
img, _, err := image.Decode(bytes.NewReader(file))
if err != nil {
log.Fatalln(err)
}
res := scale.Xbr(img, 2, true, true)
res3 := scale.Xbr(img, 3, true, true) // not work
res4 := scale.Xbr(img, 4, true, true)
_ = saveImageAsPNG(res, "output2.png")
_ = saveImageAsPNG(res3, "output3.png") // not work
_ = saveImageAsPNG(res4, "output4.png")
}