Fix image aspect ratio

This commit is contained in:
Christoph Hagen 2025-02-17 18:36:18 +01:00
parent 3df6717734
commit 9f31b1f67a

View File

@ -52,13 +52,13 @@ struct ImageSet: HtmlProducer {
let prefix1x = "/\(image.outputImageFolder)/\(maxWidth)x\(maxHeight)"
let prefix2x = "/\(image.outputImageFolder)/\(maxWidth*2)x\(maxHeight*2)"
let imageSize = (image.getImageDimensions()?.scaledToFit(in: .init(width: maxWidth, height: maxHeight)))
.map { " width='\(Int($0.width))' height='\(Int($0.height))'" }
let aspectRatio = (image.getImageDimensions()?.scaledToFit(in: .init(width: maxWidth, height: maxHeight)))
.map { " aspect-ratio='\(Int($0.width)) / \(Int($0.height))'" }
result += "<picture>"
result += "<source type='image/avif' srcset='\(prefix1x).avif 1x, \(prefix2x).avif 2x'/>"
result += "<source type='image/webp' srcset='\(prefix1x).webp 1x, \(prefix1x).webp 2x'/>"
result += "<img srcset='\(prefix2x)\(fileExtension) 2x' src='\(prefix1x)\(fileExtension)'\(imageSize ?? "") loading='lazy'\(imageAltText)\(extraAttributes)/>"
result += "<img srcset='\(prefix2x)\(fileExtension) 2x' src='\(prefix1x)\(fileExtension)'\(aspectRatio ?? "") loading='lazy'\(imageAltText)\(extraAttributes)/>"
result += "</picture>"
}
}