dont read local image file if target exists
This commit is contained in:
parent
567cd1646e
commit
9c0d959181
@ -152,6 +152,12 @@ func ImageProcessFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *
|
|||||||
if strings.HasPrefix(imgSource, "http://") || strings.HasPrefix(imgSource, "https://") {
|
if strings.HasPrefix(imgSource, "http://") || strings.HasPrefix(imgSource, "https://") {
|
||||||
// remote file
|
// remote file
|
||||||
img, p.Format, err = getImageFromURL(imgSource)
|
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
|
// build filename
|
||||||
if p.Filename == "" {
|
if p.Filename == "" {
|
||||||
var fBase string
|
var fBase string
|
||||||
@ -170,7 +176,6 @@ func ImageProcessFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *
|
|||||||
} else {
|
} else {
|
||||||
// local file
|
// local file
|
||||||
imgSource = ResolveInputPath(imgSource)
|
imgSource = ResolveInputPath(imgSource)
|
||||||
img, err = imaging.Open(imgSource, imaging.AutoOrientation(true))
|
|
||||||
if p.Filename == "" {
|
if p.Filename == "" {
|
||||||
p.Filename = fmt.Sprintf(
|
p.Filename = fmt.Sprintf(
|
||||||
"%s_%s",
|
"%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)
|
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)
|
Log.Noticef("skipped processing image from %s to %s, file already exists", imgSource, imgTarget)
|
||||||
} else {
|
} else {
|
||||||
Log.Noticef("processing image from %s to %s", imgSource, imgTarget)
|
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 {
|
switch p.Process {
|
||||||
case "resize":
|
case "resize":
|
||||||
|
Loading…
Reference in New Issue
Block a user