Implement image comparison command
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
struct ImageSet {
|
||||
struct ImageSet: HtmlProducer {
|
||||
|
||||
let image: FileResource
|
||||
|
||||
@ -12,12 +12,15 @@ struct ImageSet {
|
||||
|
||||
let description: String
|
||||
|
||||
init(image: FileResource, maxWidth: Int, maxHeight: Int, description: String, quality: CGFloat = 0.7) {
|
||||
let extraAttributes: String
|
||||
|
||||
init(image: FileResource, maxWidth: Int, maxHeight: Int, description: String, quality: CGFloat = 0.7, extraAttributes: String? = nil) {
|
||||
self.image = image
|
||||
self.maxWidth = maxWidth
|
||||
self.maxHeight = maxHeight
|
||||
self.description = description
|
||||
self.quality = quality
|
||||
self.extraAttributes = extraAttributes ?? ""
|
||||
}
|
||||
|
||||
var jobs: [ImageVersion] {
|
||||
@ -36,17 +39,16 @@ struct ImageSet {
|
||||
]
|
||||
}
|
||||
|
||||
var content: String {
|
||||
func populate(_ result: inout String) {
|
||||
let fileExtension = image.type.fileExtension.map { "." + $0 } ?? ""
|
||||
|
||||
let prefix1x = "/\(image.outputImageFolder)/\(maxWidth)x\(maxHeight)"
|
||||
let prefix2x = "/\(image.outputImageFolder)/\(maxWidth*2)x\(maxHeight*2)"
|
||||
|
||||
var result = "<picture>"
|
||||
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)' loading='lazy' alt='\(description.htmlEscaped())'/>"
|
||||
result += "<img srcset='\(prefix2x)\(fileExtension) 2x' src='\(prefix1x)\(fileExtension)' loading='lazy' alt='\(description.htmlEscaped())'\(extraAttributes)/>"
|
||||
result += "</picture>"
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user