2018-09-24 09:53:16 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-05-06 23:18:10 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2018-09-24 09:53:16 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/photoprism"
|
2019-05-02 14:10:05 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
2018-09-24 09:53:16 +02:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2018-11-17 13:57:19 +01:00
|
|
|
// Pre-renders thumbnails
|
2018-09-24 09:53:16 +02:00
|
|
|
var ThumbnailsCommand = cli.Command{
|
|
|
|
Name: "thumbnails",
|
2018-11-17 13:57:19 +01:00
|
|
|
Usage: "Pre-renders thumbnails",
|
2018-09-24 09:53:16 +02:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.IntSliceFlag{
|
|
|
|
Name: "size, s",
|
|
|
|
Usage: "Thumbnail size in pixels",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "default, d",
|
2019-05-09 07:48:41 +02:00
|
|
|
Usage: "Render default sizes: 720, 1280, 1920, 2560 and 3840px",
|
2018-09-24 09:53:16 +02:00
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "square, q",
|
|
|
|
Usage: "Square aspect ratio",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: thumbnailsAction,
|
|
|
|
}
|
|
|
|
|
2018-11-17 06:21:39 +01:00
|
|
|
func thumbnailsAction(ctx *cli.Context) error {
|
2019-05-06 23:18:10 +02:00
|
|
|
conf := config.NewConfig(ctx)
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
if err := conf.CreateDirectories(); err != nil {
|
2019-01-15 14:00:42 +01:00
|
|
|
return err
|
2018-09-24 09:53:16 +02:00
|
|
|
}
|
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
log.Infof("creating thumbnails in \"%s\"", conf.ThumbnailsPath())
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2018-11-17 06:21:39 +01:00
|
|
|
sizes := ctx.IntSlice("size")
|
2018-09-24 09:53:16 +02:00
|
|
|
|
2018-11-17 06:21:39 +01:00
|
|
|
if ctx.Bool("default") {
|
2019-05-09 07:48:41 +02:00
|
|
|
sizes = []int{720, 1280, 1920, 2560, 3840}
|
2018-09-24 09:53:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(sizes) == 0 {
|
2019-05-02 14:10:05 +02:00
|
|
|
log.Warn("no thumbnail size selected")
|
2018-09-24 09:53:16 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, size := range sizes {
|
2019-05-06 23:18:10 +02:00
|
|
|
photoprism.CreateThumbnailsFromOriginals(conf.OriginalsPath(), conf.ThumbnailsPath(), size, ctx.Bool("square"))
|
2018-09-24 09:53:16 +02:00
|
|
|
}
|
|
|
|
|
2019-05-02 14:10:05 +02:00
|
|
|
log.Info("thumbnails created")
|
2018-09-24 09:53:16 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|