webp_server_go/encoder/jpgconvert.go
Nova Kwok 4a90b18a63
Fix bug that could remove original image (#287)
* Fix bug that could remove original image

* Refine notice
2023-11-04 22:22:56 +08:00

28 lines
652 B
Go

package encoder
import (
"path/filepath"
"strings"
"github.com/jeremytorres/rawparser"
)
func ConvertRawToJPG(rawPath, optimizedPath string) (string, bool) {
if !strings.HasSuffix(strings.ToLower(rawPath), ".nef") {
// Maybe can use rawParser to convert other raw files to jpg, but I haven't tested it
return rawPath, false
}
parser, _ := rawparser.NewNefParser(true)
info := &rawparser.RawFileInfo{
File: rawPath,
Quality: 100,
DestDir: optimizedPath,
}
_, err := parser.ProcessFile(info)
if err == nil {
_, file := filepath.Split(rawPath)
return optimizedPath + file + "_extracted.jpg", true
}
return rawPath, false
}