aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go27
1 files changed, 24 insertions, 3 deletions
diff --git a/main.go b/main.go
index 971391e..5dae14e 100644
--- a/main.go
+++ b/main.go
@@ -2147,7 +2147,28 @@ func cmdCheck(fs *flag.FlagSet, args []string) error {
// --- Thumbnailing ------------------------------------------------------------
-func makeThumbnail(pathImage, pathThumb string) (int, int, error) {
+func identifyThumbnail(path string) (w, h int, err error) {
+ f, err := os.Open(path)
+ if err != nil {
+ return
+ }
+ defer f.Close()
+
+ config, err := webp.DecodeConfig(f)
+ if err != nil {
+ return
+ }
+ return config.Width, config.Height, nil
+}
+
+func makeThumbnail(load bool, pathImage, pathThumb string) (
+ w, h int, err error) {
+ if load {
+ if w, h, err = identifyThumbnail(pathThumb); err == nil {
+ return
+ }
+ }
+
thumbDirname, _ := filepath.Split(pathThumb)
if err := os.MkdirAll(thumbDirname, 0755); err != nil {
return 0, 0, err
@@ -2176,13 +2197,13 @@ func makeThumbnail(pathImage, pathThumb string) (int, int, error) {
return 0, 0, err
}
- var w, h int
_, err = fmt.Fscanf(bytes.NewReader(out), "%d %d", &w, &h)
return w, h, err
}
// cmdThumbnail generates missing thumbnails, in parallel.
func cmdThumbnail(fs *flag.FlagSet, args []string) error {
+ load := fs.Bool("load", false, "try to load existing thumbnail files")
if err := fs.Parse(args); err != nil {
return err
}
@@ -2215,7 +2236,7 @@ func cmdThumbnail(fs *flag.FlagSet, args []string) error {
return parallelize(hexSHA1, func(sha1 string) (message string, err error) {
pathImage := imagePath(sha1)
pathThumb := thumbPath(sha1)
- w, h, err := makeThumbnail(pathImage, pathThumb)
+ w, h, err := makeThumbnail(*load, pathImage, pathThumb)
if err != nil {
if ee, ok := err.(*exec.ExitError); ok {
return string(ee.Stderr), nil