Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/HandySwiftUI/Extensions/ImageExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension Image {
else { return nil }

return bitmapImage.representation(
using: .jpeg2000,
using: .jpeg,
properties: [NSBitmapImageRep.PropertyKey.compressionFactor: NSNumber(value: compressionQuality)]
)
}
Expand Down
22 changes: 22 additions & 0 deletions Tests/HandySwiftUITests/ImageExtTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#if os(macOS)
import AppKit
import Testing

@testable import HandySwiftUI

struct ImageExtTests {
@Test
func jpegDataEncodesAsJPEG() throws {
let image = NSImage(size: NSSize(width: 8, height: 8), flipped: false) { rect in
NSColor.systemRed.setFill()
rect.fill()
return true
}

let data = try #require(image.jpegData(compressionQuality: 0.8))

// Every JPEG file starts with the SOI marker followed by the next marker's 0xFF (JPEG 2000 starts with 0x00 0x00 0x00 0x0C)
#expect(Array(data.prefix(3)) == [0xFF, 0xD8, 0xFF])
}
}
#endif
Loading