dont read local image file if target exists

This commit is contained in:
Sebastian Frank 2019-03-10 16:36:20 +01:00
parent 567cd1646e
commit 9c0d959181
Signed by: apairon
GPG Key ID: 7270D06DDA7FE8C3

View File

@ -152,6 +152,12 @@ func ImageProcessFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *
if strings.HasPrefix(imgSource, "http://") || strings.HasPrefix(imgSource, "https://") {
// remote file
img, p.Format, err = getImageFromURL(imgSource)
if err != nil {
return nil, &pongo2.Error{
Sender: "filter:image_resize",
OrigError: fmt.Errorf("could not open image '%s': %s", imgSource, err),
}
}
// build filename
if p.Filename == "" {
var fBase string
@ -170,7 +176,6 @@ func ImageProcessFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *
} else {
// local file
imgSource = ResolveInputPath(imgSource)
img, err = imaging.Open(imgSource, imaging.AutoOrientation(true))
if p.Filename == "" {
p.Filename = fmt.Sprintf(
"%s_%s",
@ -179,12 +184,6 @@ func ImageProcessFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *
)
}
}
if err != nil {
return nil, &pongo2.Error{
Sender: "filter:image_resize",
OrigError: fmt.Errorf("could not open image '%s': %s", imgSource, err),
}
}
imgTarget := ResolveOutputPath(p.Filename)
@ -192,6 +191,17 @@ func ImageProcessFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *
Log.Noticef("skipped processing image from %s to %s, file already exists", imgSource, imgTarget)
} else {
Log.Noticef("processing image from %s to %s", imgSource, imgTarget)
if strings.HasPrefix(imgSource, "http://") || strings.HasPrefix(imgSource, "https://") {
// webrequest before finding target filename, because of file format in filename
} else {
img, err = imaging.Open(imgSource, imaging.AutoOrientation(true))
if err != nil {
return nil, &pongo2.Error{
Sender: "filter:image_resize",
OrigError: fmt.Errorf("could not open image '%s': %s", imgSource, err),
}
}
}
switch p.Process {
case "resize":