mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 21:09:05 +00:00
Switch to Debian testing and imagemagick. (#1021)
This commit is contained in:
@@ -18,7 +18,7 @@ require (
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/strukturag/libheif v1.15.1
|
||||
github.com/strukturag/libheif v1.17.6
|
||||
github.com/vektah/gqlparser/v2 v2.5.16
|
||||
github.com/wsxiaoys/terminal v0.0.0-20160513160801-0940f3fc43a0
|
||||
github.com/xor-gate/goexif2 v1.1.0
|
||||
|
||||
@@ -91,8 +91,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/strukturag/libheif v1.15.1 h1:PWMRTk+9HG0a9avvlV597iI0AdHk25zKVV33lSl6a+I=
|
||||
github.com/strukturag/libheif v1.15.1/go.mod h1:E/PNRlmVtrtj9j2AvBZlrO4dsBDu6KfwDZn7X1Ce8Ks=
|
||||
github.com/strukturag/libheif v1.17.6 h1:UFz4FI7kKLINWyL7bcNEBu4gZxK7rHRkwq49IOzHyvE=
|
||||
github.com/strukturag/libheif v1.17.6/go.mod h1:E/PNRlmVtrtj9j2AvBZlrO4dsBDu6KfwDZn7X1Ce8Ks=
|
||||
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
|
||||
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
|
||||
github.com/vektah/gqlparser/v2 v2.5.16 h1:1gcmLTvs3JLKXckwCwlUagVn/IlV2bwqle0vJ0vy5p8=
|
||||
|
||||
@@ -22,12 +22,12 @@ import (
|
||||
)
|
||||
|
||||
var thumbFilter = map[models.ThumbnailFilter]imaging.ResampleFilter{
|
||||
models.ThumbnailFilterNearestNeighbor: imaging.NearestNeighbor,
|
||||
models.ThumbnailFilterBox: imaging.Box,
|
||||
models.ThumbnailFilterLinear: imaging.Linear,
|
||||
models.ThumbnailFilterMitchellNetravali: imaging.MitchellNetravali,
|
||||
models.ThumbnailFilterCatmullRom: imaging.CatmullRom,
|
||||
models.ThumbnailFilterLanczos: imaging.Lanczos,
|
||||
models.ThumbnailFilterNearestNeighbor: imaging.NearestNeighbor,
|
||||
models.ThumbnailFilterBox: imaging.Box,
|
||||
models.ThumbnailFilterLinear: imaging.Linear,
|
||||
models.ThumbnailFilterMitchellNetravali: imaging.MitchellNetravali,
|
||||
models.ThumbnailFilterCatmullRom: imaging.CatmullRom,
|
||||
models.ThumbnailFilterLanczos: imaging.Lanczos,
|
||||
}
|
||||
|
||||
func EncodeThumbnail(db *gorm.DB, inputPath string, outputPath string) (*media_utils.PhotoDimensions, error) {
|
||||
@@ -108,10 +108,10 @@ func (img *EncodeMediaData) EncodeHighRes(outputPath string) error {
|
||||
return errors.New("could not convert photo as file format is not supported")
|
||||
}
|
||||
|
||||
// Use darktable if there is no counterpart JPEG file to use instead
|
||||
// Use ImageMagick if there is no counterpart JPEG file to use instead
|
||||
if contentType.IsRaw() && img.CounterpartPath == nil {
|
||||
if executable_worker.DarktableCli.IsInstalled() {
|
||||
err := executable_worker.DarktableCli.EncodeJpeg(img.Media.Path, outputPath, 70)
|
||||
if executable_worker.MagickCli.IsInstalled() {
|
||||
err := executable_worker.MagickCli.EncodeJpeg(img.Media.Path, outputPath, 70)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ package executable_worker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
@@ -14,18 +12,18 @@ import (
|
||||
)
|
||||
|
||||
func InitializeExecutableWorkers() {
|
||||
DarktableCli = newDarktableWorker()
|
||||
MagickCli = newMagickWorker()
|
||||
FfmpegCli = newFfmpegWorker()
|
||||
}
|
||||
|
||||
var DarktableCli *DarktableWorker = nil
|
||||
var MagickCli *MagickWorker = nil
|
||||
var FfmpegCli *FfmpegWorker = nil
|
||||
|
||||
type ExecutableWorker interface {
|
||||
Path() string
|
||||
}
|
||||
|
||||
type DarktableWorker struct {
|
||||
type MagickWorker struct {
|
||||
path string
|
||||
}
|
||||
|
||||
@@ -33,25 +31,25 @@ type FfmpegWorker struct {
|
||||
path string
|
||||
}
|
||||
|
||||
func newDarktableWorker() *DarktableWorker {
|
||||
func newMagickWorker() *MagickWorker {
|
||||
if utils.EnvDisableRawProcessing.GetBool() {
|
||||
log.Printf("Executable worker disabled (%s=1): darktable\n", utils.EnvDisableRawProcessing.GetName())
|
||||
log.Printf("Executable worker disabled (%s=1): ImageMagick\n", utils.EnvDisableRawProcessing.GetName())
|
||||
return nil
|
||||
}
|
||||
|
||||
path, err := exec.LookPath("darktable-cli")
|
||||
path, err := exec.LookPath("convert")
|
||||
if err != nil {
|
||||
log.Println("Executable worker not found: darktable")
|
||||
log.Println("Executable worker not found: ImageMagick convert")
|
||||
} else {
|
||||
version, err := exec.Command(path, "--version").Output()
|
||||
if err != nil {
|
||||
log.Printf("Error getting version of darktable: %s\n", err)
|
||||
log.Printf("Error getting version of ImageMagick convert: %s\n", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Printf("Found executable worker: darktable (%s)\n", strings.Split(string(version), "\n")[0])
|
||||
log.Printf("Found executable worker: ImageMagick convert (%s)\n", strings.Split(string(version), "\n")[0])
|
||||
|
||||
return &DarktableWorker{
|
||||
return &MagickWorker{
|
||||
path: path,
|
||||
}
|
||||
}
|
||||
@@ -85,7 +83,7 @@ func newFfmpegWorker() *FfmpegWorker {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (worker *DarktableWorker) IsInstalled() bool {
|
||||
func (worker *MagickWorker) IsInstalled() bool {
|
||||
return worker != nil
|
||||
}
|
||||
|
||||
@@ -93,27 +91,17 @@ func (worker *FfmpegWorker) IsInstalled() bool {
|
||||
return worker != nil
|
||||
}
|
||||
|
||||
func (worker *DarktableWorker) EncodeJpeg(inputPath string, outputPath string, jpegQuality int) error {
|
||||
tmpDir, err := ioutil.TempDir("/tmp", "photoview-darktable")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
func (worker *MagickWorker) EncodeJpeg(inputPath string, outputPath string, jpegQuality int) error {
|
||||
args := []string{
|
||||
inputPath,
|
||||
"-quality", fmt.Sprintf("%d", jpegQuality),
|
||||
outputPath,
|
||||
"--core",
|
||||
"--conf",
|
||||
fmt.Sprintf("plugins/imageio/format/jpeg/quality=%d", jpegQuality),
|
||||
"--configdir",
|
||||
tmpDir,
|
||||
}
|
||||
|
||||
cmd := exec.Command(worker.path, args...)
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return errors.Wrapf(err, "encoding image using: %s %v", worker.path, args)
|
||||
return fmt.Errorf("encoding image with \"%s %v\" error: %w", worker.path, args, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package executable_worker_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/photoview/photoview/api/test_utils"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
os.Exit(test_utils.IntegrationTestRun(m))
|
||||
}
|
||||
|
||||
func setPathWithCurrent(paths ...string) func() {
|
||||
_, file, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
return func() {}
|
||||
}
|
||||
|
||||
base := filepath.Dir(file)
|
||||
|
||||
for i, path := range paths {
|
||||
paths[i] = filepath.Join(base, path)
|
||||
}
|
||||
|
||||
originalPath := os.Getenv("PATH")
|
||||
os.Setenv("PATH", strings.Join(paths, ":"))
|
||||
|
||||
return func() {
|
||||
os.Setenv("PATH", originalPath)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package executable_worker_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/photoview/photoview/api/scanner/media_encoding/executable_worker"
|
||||
)
|
||||
|
||||
func TestMagickWorkerNotExist(t *testing.T) {
|
||||
done := setPathWithCurrent()
|
||||
defer done()
|
||||
|
||||
executable_worker.InitializeExecutableWorkers()
|
||||
|
||||
if executable_worker.MagickCli.IsInstalled() {
|
||||
t.Error("MagickCli should not be installed, but is found:", executable_worker.MagickCli)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMagickWorkerIgnore(t *testing.T) {
|
||||
done := setPathWithCurrent("./testdata/bin")
|
||||
defer done()
|
||||
|
||||
org := os.Getenv("PHOTOVIEW_DISABLE_RAW_PROCESSING")
|
||||
os.Setenv("PHOTOVIEW_DISABLE_RAW_PROCESSING", "true")
|
||||
defer os.Setenv("PHOTOVIEW_DISABLE_RAW_PROCESSING", org)
|
||||
|
||||
executable_worker.InitializeExecutableWorkers()
|
||||
|
||||
if executable_worker.MagickCli.IsInstalled() {
|
||||
t.Error("MagickCli should not be installed, but is found:", executable_worker.MagickCli)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMagickWorker(t *testing.T) {
|
||||
done := setPathWithCurrent("./testdata/bin")
|
||||
defer done()
|
||||
|
||||
executable_worker.InitializeExecutableWorkers()
|
||||
|
||||
if !executable_worker.MagickCli.IsInstalled() {
|
||||
t.Error("MagickCli should be installed")
|
||||
}
|
||||
|
||||
t.Run("Failed", func(t *testing.T) {
|
||||
err := executable_worker.MagickCli.EncodeJpeg("input", "output", 0)
|
||||
if err == nil {
|
||||
t.Fatalf("MagickCli.EncodeJpeg(\"input\", \"output\", 0) = nil, should be an error.")
|
||||
}
|
||||
if got, want := err.Error(), "^encoding image with \".*?/testdata/bin/convert .*?\" error: .*$"; !regexp.MustCompile(want).MatchString(got) {
|
||||
t.Errorf("MagickCli.EncodeJpeg(\"input\", \"output\", 0) = %q, should be as reg pattern %q", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Succeeded", func(t *testing.T) {
|
||||
err := executable_worker.MagickCli.EncodeJpeg("input", "output", 70)
|
||||
if err != nil {
|
||||
t.Fatalf("MagickCli.EncodeJpeg(\"input\", \"output\", 0) = %v, should be nil.", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
13
api/scanner/media_encoding/executable_worker/testdata/bin/convert
vendored
Executable file
13
api/scanner/media_encoding/executable_worker/testdata/bin/convert
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
case "$1" in
|
||||
"--version")
|
||||
echo convert: version fake
|
||||
;;
|
||||
esac
|
||||
|
||||
echo $@
|
||||
if [ "$3" = "0" ] # quality parameter
|
||||
then
|
||||
exit -1
|
||||
fi
|
||||
@@ -260,7 +260,7 @@ func (imgType *MediaType) IsSupported() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if executable_worker.DarktableCli.IsInstalled() && imgType.IsRaw() {
|
||||
if executable_worker.MagickCli.IsInstalled() && imgType.IsRaw() {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user