diff --git a/upload/upload.go b/upload/upload.go index c2dcb39..d1a4584 100644 --- a/upload/upload.go +++ b/upload/upload.go @@ -21,7 +21,36 @@ const ( RESIZE_THUMB = "/usr/bin/convert -resize 60 -quality 60 " ) +func resize(folder, name, extension string) (string, string) { + imgPath := folder + name + extension + resize := append(strings.Split(RESIZE, " "), imgPath, imgPath) + cmd := exec.Command(resize[0], resize[1:]...) + cmd.Run() + imgPathSmall := folder + name + "_small" + extension + resize = append(strings.Split(RESIZE_THUMB, " "), imgPath, imgPathSmall) + cmd = exec.Command(resize[0], resize[1:]...) + cmd.Run() + return "/" + imgPath, "/" + imgPathSmall +} + func getCover(e *epub.Epub, path string) (string, string) { + folder := COVER_PATH + path[:1] + "/" + os.Mkdir(folder, os.ModePerm) + + /* Try first common names */ + imgPath := folder + path + ".jpg" + file, _ := os.Create(imgPath) + defer file.Close() + n, _ := file.Write(e.Data("cover.jpg")) + if n != 0 { + return resize(folder, path, ".jpg") + } + n, _ = file.Write(e.Data("cover.jpeg")) + if n != 0 { + return resize(folder, path, ".jpg") + } + defer os.Remove(imgPath) + exp, _ := regexp.Compile("