2018-09-24 09:53:16 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-10-31 07:14:33 +01:00
|
|
|
"log"
|
|
|
|
|
2018-09-24 09:53:16 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/photoprism"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var ThumbnailsCommand = cli.Command{
|
|
|
|
Name: "thumbnails",
|
|
|
|
Usage: "Creates thumbnails",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.IntSliceFlag{
|
|
|
|
Name: "size, s",
|
|
|
|
Usage: "Thumbnail size in pixels",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "default, d",
|
|
|
|
Usage: "Render default sizes: 320, 500, 640, 1280, 1920 and 2560px",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "square, q",
|
|
|
|
Usage: "Square aspect ratio",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: thumbnailsAction,
|
|
|
|
}
|
|
|
|
|
2018-10-31 02:42:54 +01:00
|
|
|
// Creates thumbnail; called by ThumbnailsCommand
|
2018-09-24 09:53:16 +02:00
|
|
|
func thumbnailsAction(context *cli.Context) error {
|
|
|
|
conf := photoprism.NewConfig(context)
|
|
|
|
|
|
|
|
if err := conf.CreateDirectories(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Creating thumbnails in %s...\n", conf.ThumbnailsPath)
|
|
|
|
|
|
|
|
sizes := context.IntSlice("size")
|
|
|
|
|
|
|
|
if context.Bool("default") {
|
|
|
|
sizes = []int{320, 500, 640, 1280, 1920, 2560}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(sizes) == 0 {
|
|
|
|
fmt.Println("No sizes selected. Nothing to do.")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, size := range sizes {
|
|
|
|
photoprism.CreateThumbnailsFromOriginals(conf.OriginalsPath, conf.ThumbnailsPath, size, context.Bool("square"))
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Done.")
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|