Fix aspect ratio for non-square album art.

This commit is contained in:
Jason Walton 2020-11-22 11:13:38 -05:00 committed by Deluan Quintão
parent 3996764486
commit 69b2fe92f5
2 changed files with 11 additions and 1 deletions

View File

@ -171,7 +171,16 @@ func resizeImage(reader io.Reader, size int) ([]byte, error) {
if err != nil {
return nil, err
}
m := imaging.Resize(img, size, size, imaging.Lanczos)
// Preserve the aspect ratio of the image.
var m *image.NRGBA
bounds := img.Bounds()
if bounds.Max.X > bounds.Max.Y {
m = imaging.Resize(img, size, 0, imaging.Lanczos)
} else {
m = imaging.Resize(img, 0, size, imaging.Lanczos)
}
buf := new(bytes.Buffer)
err = jpeg.Encode(buf, m, &jpeg.Options{Quality: conf.Server.CoverJpegQuality})
return buf.Bytes(), err

View File

@ -77,6 +77,7 @@ const useCoverStyles = makeStyles({
cover: {
display: 'inline-block',
width: '100%',
'object-fit': 'contain',
height: (props) => props.height,
},
})