func writeImage(img image.Image, format string, w io.Writer) error {
	if format == "png" {
		return png.Encode(w, img)
	}
	return jpeg.Encode(w, img, &jpeg.Options{Config.jpegQuality})
}
Writes a given image of the given format to the given destination.
Returns error.
package main
import (
	"fmt"
	"image"
	"image/jpeg"
	"image/png"
	"io"
	"regexp"
	"strconv"
)
var (
	scaledPathRe    = regexp.MustCompile("(.+)@(\\d+)x\\.([^\\.]+)$")
	notScaledPathRe = regexp.MustCompile("(.+)\\.([^\\.]+)$")
)