diff --git a/README.md b/README.md index 3f513cf..da23e64 100644 --- a/README.md +++ b/README.md @@ -1 +1,33 @@ -# HEIC2JPG \ No newline at end of file +# HEIC2JPG + +## Usage + +To convert a single file: + +`heic2jpg myfile.heic` + +To convert all files in a folder: + +`heic2jpg -dir ./MyPhotos -r` + +You can create new files in another folder with the `-o` argument + +Other arguments are available on `-h` + +## Build + +The tool contains C code, so you need to activate cgo to compile it. + +`go build` + +I compile with the following command (not sure if it speeds up conversion, but it makes the binary lighter): + +On Linux: +```bash +GOAMD64='v3' go build -a -v -ldflags="-s -w" -buildvcs=false +``` + +On Windows (PowerShell): +```ps +$env:GOAMD64 = 'v3'; go build -a -v -ldflags="-s -w" -buildvcs=false +``` \ No newline at end of file diff --git a/go.mod b/go.mod index 2d702e0..348a1cc 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/mojitaurelie/heic2jpg -go 1.20 +go 1.21 require github.com/adrium/goheif v0.0.0-20230113233934-ca402e77a786 diff --git a/main.go b/main.go index 9b6f235..e6f0213 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,18 @@ import ( "github.com/mojitaurelie/heic2jpg/exif" ) +const ( + VERSION = "0.1.0" + + usageDescription = `heic2jpg - v%s.%s.%s.%s +Note: is ignored when -dir is set + + Usage: heic2jpg [OPTIONS] + +OPTIONS: +` +) + type ( filer interface { IsDir() bool @@ -25,11 +37,15 @@ type ( ) func usage() { - fmt.Printf("Usage: %s [OPTIONS] \n\n", os.Args[0]) - fmt.Printf("Note: is ignored when -dir is set\n\nOPTIONS:\n") + fmt.Printf(usageDescription, VERSION, runtime.Version(), runtime.GOOS, runtime.GOARCH) flag.PrintDefaults() } +func version() { + fmt.Printf("heic2jpg - v%s.%s.%s.%s\n", VERSION, runtime.Version(), runtime.GOOS, runtime.GOARCH) + os.Exit(0) +} + func main() { go func() { if r := recover(); r != nil { @@ -48,8 +64,13 @@ func main() { removeOrig := flag.Bool("remove-original", false, "Remove the heic file after conversion") overwriteOut := flag.Bool("overwrite", false, "Overwrite file if already exists") outPath := flag.String("o", "", "Output directory") + v := flag.Bool("v", false, "Show version") flag.Parse() + if *v { + version() + } + if *jpegQuality < 1 || *jpegQuality > 100 { fmt.Println("W: Illegal value for jpeg quality, quality is set to ", jpeg.DefaultQuality) *jpegQuality = jpeg.DefaultQuality