webp_server_go/encoder/rawconvert.go

28 lines
763 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package encoder
import (
"path/filepath"
"github.com/jeremytorres/rawparser"
)
// ConvertRawToJPG 将原始图像文件转换为JPEG格式并保存到优化路径。
// rawPath: 原始图像文件的路径。
// optimizedPath: 转换后的JPEG文件保存路径。
// 返回值: 成功时返回转换后的JPEG文件路径和true失败时返回原始路径和false。
func ConvertRawToJPG(rawPath, optimizedPath string) (string, bool) {
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
}