I am building a Go based image processing worker for my web application. I am trying to be idiomatic, but I am new to Go. Any feedback, is appreciated. This program uses bimg to generate 4 square images based on top, left, width, height, which come from a client side cropping library (croppie.js)
package main
import (
"log"
"os"
"fmt"
"strings"
"gopkg.in/h2non/bimg.v1"
)
var sizes = [3]int{128, 256, 512}
func resizeImage(img []byte, width int, height int, name string) (err error){
options := bimg.Options{
Width: width,
Height: height,
}
var thumb []byte
thumb, err = bimg.Resize(img, options)
if err != nil {
log.Println(os.Stderr, err)
return err
}
err = bimg.Write(name, thumb)
return
}
func processImage(top, left, width, height int, filename string) (err error){
var buffer, original []byte
var image *bimg.Image
var fileBaseName = strings.Split(filename, ".")[0]
buffer, err = bimg.Read(filename)
if err != nil {
log.Println(os.Stderr, err)
}
image = bimg.NewImage(buffer)
original, err = image.Extract(left, top, width, height)
if err != nil {
return err
}
err = bimg.Write(fileBaseName + "_original.jpg", original)
if err != nil {
return err
}
for i := 0; i < len(sizes); i++ {
size := sizes[i]
err = resizeImage(original, size, size, fmt.Sprintf(fileBaseName + "_%d.jpg", size))
if(err != nil){
log.Println(os.Stderr, err)
return err
}
}
return
}
func main() {
err := processImage(50,50,400,400, "test2.jpeg")
if(err != nil){
log.Println(os.Stderr, err)
}
}