Last active
December 21, 2015 15:29
-
-
Save ifq/6326773 to your computer and use it in GitHub Desktop.
thumbnail generate, use vipsthumbnail cmdtool which comes from libvips. It takes 0.3s to generate a thumbnail from a 5Mbyte photo on one cpu core.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func ResizeImg(spath string, tpath []string, size []image.Point) (int, error) { | |
if len(tpath) != len(size) { | |
log.Println("GetImgThumb: ", tpath, size) | |
return 0, errors.New("GetImgThumb length unsafe") | |
} | |
cnt := 0 | |
for i, tgt := range tpath { | |
log.Println("+++", spath, tgt) | |
_, err := os.Stat(tgt) | |
if err != nil { | |
if !os.IsNotExist(err) { | |
log.Println(err) | |
continue | |
} | |
// 创建文件夹 | |
os.MkdirAll(filepath.Dir(tgt), 0755) | |
log.Println("=== ", tgt) | |
cmd := exec.Command("vipsthumbnail", spath, "-o", tgt, "-s", strconv.Itoa(size[i].X)) | |
err := cmd.Run() | |
if err != nil { | |
log.Println("run err:", spath, tgt, err) | |
} | |
cnt++ | |
} | |
} | |
return cnt, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment