Implement size and compression print
This commit is contained in:
15
main.go
15
main.go
@@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
var codecs = map[string]codec.Coder{
|
var codecs = map[string]codec.Coder{
|
||||||
".jpg": codec.JPGCoder{},
|
".jpg": codec.JPGCoder{},
|
||||||
".jpeg": codec.JPGCoder{},
|
".jpeg": codec.JPGCoder{},
|
||||||
".png": codec.PNGCoder{},
|
".png": codec.PNGCoder{},
|
||||||
".webp": codec.WebpCoder{},
|
".webp": codec.WebpCoder{},
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ func main() {
|
|||||||
log.Printf("Using quality: %d", *quality)
|
log.Printf("Using quality: %d", *quality)
|
||||||
log.Printf("Transcoding to: %s", *to)
|
log.Printf("Transcoding to: %s", *to)
|
||||||
log.Printf("Nosafe mode: %v", *nosafe)
|
log.Printf("Nosafe mode: %v", *nosafe)
|
||||||
log.Printf("Remove mode: %v", *rm)
|
log.Printf("Remove mode: %v", *rm)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, file := range flag.Args() {
|
for _, file := range flag.Args() {
|
||||||
@@ -65,7 +65,6 @@ func main() {
|
|||||||
Error.Printf("No encoder found for file: %s", file)
|
Error.Printf("No encoder found for file: %s", file)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Printf("%#v", coder)
|
|
||||||
|
|
||||||
filename := filepath.Base(file)
|
filename := filepath.Base(file)
|
||||||
if *nosafe {
|
if *nosafe {
|
||||||
@@ -82,6 +81,12 @@ func main() {
|
|||||||
Error.Printf("Failed to open file: %v", err)
|
Error.Printf("Failed to open file: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
stat, err := filehandle.Stat()
|
||||||
|
if err != nil {
|
||||||
|
Error.Printf("Failed to get file stats: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
originalSize := stat.Size()
|
||||||
|
|
||||||
log.Printf("Decoding %s", file)
|
log.Printf("Decoding %s", file)
|
||||||
image, err := coder.Decode(filehandle)
|
image, err := coder.Decode(filehandle)
|
||||||
@@ -111,7 +116,7 @@ func main() {
|
|||||||
Error.Printf("Failed to write file %s: %v", newfile, err)
|
Error.Printf("Failed to write file %s: %v", newfile, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Printf("Wrote %d bytes to %s", n, newfile)
|
log.Printf("Wrote %dKB; Old size: %dKB; Compression: %.2f", n/1024, originalSize/1024, float32(n)/float32(originalSize))
|
||||||
|
|
||||||
if *rm {
|
if *rm {
|
||||||
if file == newfile {
|
if file == newfile {
|
||||||
@@ -120,7 +125,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
log.Printf("Removing %s", file)
|
log.Printf("Removing %s", file)
|
||||||
err = os.Remove(file)
|
err = os.Remove(file)
|
||||||
if err!= nil {
|
if err != nil {
|
||||||
Error.Printf("Failed to remove file %v: %v", file, err)
|
Error.Printf("Failed to remove file %v: %v", file, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user