Handle PNG EXIF and distinguish transient encoder crashes from invalid images
This commit is contained in:
@@ -47,19 +47,23 @@ func Transform(input, dir string, versions ...int) error {
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
c, _, e := image.DecodeConfig(f)
|
||||
c, format, e := image.DecodeConfig(f)
|
||||
f.Close()
|
||||
if e != nil || c.Width < 1 || c.Height < 1 || int64(c.Width)*int64(c.Height) > maxPixels {
|
||||
return fmt.Errorf("invalid_image")
|
||||
return ErrInvalidImage
|
||||
}
|
||||
img, e := imaging.Open(input, imaging.AutoOrientation(true))
|
||||
if e != nil {
|
||||
return fmt.Errorf("invalid_image")
|
||||
return ErrInvalidImage
|
||||
}
|
||||
bounds := img.Bounds()
|
||||
var oriented image.Image = img
|
||||
if format == "png" {
|
||||
oriented = orientPNG(img, pngOrientation(input))
|
||||
}
|
||||
bounds := oriented.Bounds()
|
||||
white := image.NewNRGBA(bounds)
|
||||
draw.Draw(white, bounds, &image.Uniform{C: color.White}, image.Point{}, draw.Src)
|
||||
draw.Draw(white, bounds, img, bounds.Min, draw.Over)
|
||||
draw.Draw(white, bounds, oriented, bounds.Min, draw.Over)
|
||||
w, h := fitDimensions(bounds.Dx(), bounds.Dy(), 256)
|
||||
thumbnail := imaging.Resize(white, w, h, imaging.Lanczos)
|
||||
crop := imaging.Fill(white, 128, 128, imaging.Center, imaging.Lanczos)
|
||||
|
||||
Reference in New Issue
Block a user