diff --git a/img/img.go b/img/img.go index 9a4bb83..8962a82 100644 --- a/img/img.go +++ b/img/img.go @@ -26,8 +26,22 @@ func Decode(filepath string) (image.Image, error) { return img, nil } -// Resize resizes an image to the specified width and height. +// Resizes an image to the specified width and height. // If either width or height is 0, the aspect ratio is maintained. +// If the output of the resize has an uneven height, a final resize is done to make it even. +// This prevents a line of black pixels from appearing at the bottom of the image when rendered. func Resize(image image.Image, width, height int) image.Image { - return resize.Resize(uint(width), uint(height), image, resize.Lanczos3) + image = resize.Resize(uint(width), uint(height), image, resize.Lanczos3) + + // check if the height is even and resize again if it is not + if image.Bounds().Dy()%2 != 0 { + image = resize.Resize( + uint(image.Bounds().Dx()), + uint(image.Bounds().Dy()+1), + image, + resize.Lanczos3, + ) + } + + return image }